在我目前的测试中,我有一个继承自“celestialClass”的类“PlanetClass”。我的问题是当我释放我的“PlanetClass”对象时,它会通过两个 dealloc 方法,首先释放 Planet 对象,然后释放 Celestial 对象。我将 dealloc 添加到 celestial 以确保我可以释放 iVar“bodyName”,我想我有这个权利,我只是想检查一下?
@implementation CelestialClass
- (NSString *)bodyName {
return [[bodyName retain] autorelease];
}
- (void)setBodyName:(NSString *)newBodyName {
if (bodyName != newBodyName) {
[bodyName release];
bodyName = [newBodyName copy];
}
}
- (void) dealloc {
NSLog(@"_deal_CB: %@", self);
[bodyName release];
bodyName = nil;
[super dealloc];
}
@end
@implementation PlanetClass
- (int *)oceanDepth {
return oceanDepth;
}
- (void)setOceanDepth:(int *)value {
oceanDepth = value;
}
- (void) dealloc {
NSLog(@"_deal: %@", self);
[super dealloc];
}
@end
干杯-加里-