请参阅所附图像以供参考。所有viewControllers
已从应用程序中删除,但是Memory Debugger显示其实例及其所有属性。当我单击Memory Debugger的Show Only Leaked blocks
筛选器时,viewControllers
和其他实例没有出现在其中。这是否意味着没有泄漏?
我该如何解决问题。这是什么意思?
我在PKYStepper
的CartViewController
中确实有cellForRowAtIndexPath
块(步进在我的UIControl
中为TableViewCell
),如下所示:
PKYStepper *qtyStepper = [cell viewWithTag:993];
qtyStepper.tappedCallback = ^(PKYStepper *stepper) {
NSLog(@"Tapped!");
rowSelected = indexPath;
if (((Dish*)((MenuSubSection*)_section.subSections[0]).dishesArray[indexPath.row]).disheOptions.count)
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
NSBundle* bun = [NSBundle bundleWithIdentifier:@"com.test.test"];
DishItemOption *dishOptions = [[bun loadNibNamed:@"DishItemOption" owner:self options:nil] objectAtIndex:0];
dishOptions.frame = CGRectMake(0, 0, window.frame.size.width, window.frame.size.height);
dishOptions.dish = [[Dish alloc] initWithDishObject:((Dish*)((MenuSubSection*)_section.subSections[0]).dishesArray[indexPath.row])];
dishOptions.delegate = self;
[window addSubview:dishOptions];
}
};
如何使其引用弱自我?
看起来您似乎已经在某种回调块中捕获了视图控制器。
特别是PKYStepper
似乎有一个强烈引用视图控制器的回调块。请确保该引用较弱,或者确保在拆除视图控制器时已正确破坏该块。
找到了解决方案。将我的回调更新为以下内容:
__weak typeof(self) weakSelf = self;
qtyStepper.incrementCallback = ^(PKYStepper *stepper, float newValue) {
CartViewController *sSelf = weakSelf;
[sSelf updateTotalCharges]; //Had to use WEAKSELF in the callback!
};