I'm sorting out some memory issues with my iPhone app and I've just been thinking about some basics. If I setup an ivar and never end up using it in the lifespan of my object, when I call dealloc on it, will that cause a problem? E.g.
@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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…