我正在整理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