Mic*_*all 38 iphone cocoa cocoa-touch memory-management objective-c
我正在用我的iPhone应用程序解决一些内存问题,我一直在考虑一些基础知识.如果我设置了一个ivar并且永远不会在我的对象的生命周期中使用它,当我在其上调用dealloc时,会导致问题吗?例如
@interface testClass {
id myobject;
}
@property (nonatomic, retain) id myobject;
@end
@implementation testClass
@synthesize myobject;
- (id)init {
...
// Do I have to set myobject to nil here?
// So if myobject isn't used the dealloc call to nil
// will be okay? Or can you release the variable without
// having set every object to nil that you may may not use
...
}
...
// Somewhere in the code, myobject may be set to
// an instance of an object via self.myobject = [AnObject grabAnObject]
// but the object may be left alone
...
- (void)dealloc {
[myobject release];
[super dealloc];
}
@end
Run Code Online (Sandbox Code Playgroud)
BJ *_*mer 11
是的,ivars总是被初始化为0/nil/NULL/NO /等.
但是,如果它可以帮助您了解正在发生的事情,那就去吧.性能影响可以忽略不计.您不需要这样做,但如果您这样做,它不会导致任何问题.
| 归档时间: |
|
| 查看次数: |
11923 次 |
| 最近记录: |