Xcode内存调试器显示已删除对象的实例-iOS

问题描述 投票:0回答:2

请参阅所附图像以供参考。所有viewControllers已从应用程序中删除,但是Memory Debugger显示其实例及其所有属性。当我单击Memory Debugger的Show Only Leaked blocks筛选器时,viewControllers和其他实例没有出现在其中。这是否意味着没有泄漏?

我该如何解决问题。这是什么意思?

enter image description here

我在PKYStepperCartViewController中确实有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];
            }

        };

如何使其引用弱自我?

ios objective-c xcode memory-management memory-leaks
2个回答
2
投票

看起来您似乎已经在某种回调块中捕获了视图控制器。

特别是PKYStepper似乎有一个强烈引用视图控制器的回调块。请确保该引用较弱,或者确保在拆除视图控制器时已正确破坏该块。


1
投票

找到了解决方案。将我的回调更新为以下内容:

__weak typeof(self) weakSelf = self;

    qtyStepper.incrementCallback = ^(PKYStepper *stepper, float newValue) {

        CartViewController *sSelf = weakSelf;

        [sSelf updateTotalCharges]; //Had to use WEAKSELF in the callback!

    };
© www.soinside.com 2019 - 2024. All rights reserved.