小编Ale*_*ing的帖子

ARC内存管理:@Property(非原子,强)VS实例变量

我在Xcode(Allocations)中使用分析工具发现的是,当你淘汰一个属性时,它不会被解除分配,直到父类被填空.现在让我们假设您要确保不在内存中保留昂贵的模态视图控制器(假设它不会经常使用),如果昂贵的VC是属性,则该属性的已分配内存不会当属性被填空时释放,这意味着当用户想再次使用昂贵的VC时,我们每次都会分配相同数量的内存.由于图表不断攀升,因此很容易在剖析器中发现.

但是,如果我只将昂贵的VC定义为实例变量并定义我自己的setter和getter,那么当变量被填空时,分析器分配图实际上会立即减少,并且在每次新分配时返回相同的量.

所以我的问题是,为什么变量'似乎'在被定义为实例变量时被释放,但在定义为属性时却没有?

// What I call defining something as an instance variable:
@interface SomeViewController ()
{
    UIPopoverController *somePopover;
}

// What I call defining something as a property
@property (nonatomic,strong) UIPopoverController *somePopover;

// Nilling out a property which does not get allocated unless it does not have a parent (root node memory graph wise)
self.somePopover = nil;

// Nilling out an instance variable which does make the memory graph in the profiler go down by the same amount it …
Run Code Online (Sandbox Code Playgroud)

objective-c ios automatic-ref-counting

2
推荐指数
1
解决办法
868
查看次数

标签 统计

automatic-ref-counting ×1

ios ×1

objective-c ×1