나의 현재 테스트에서 나는 "celestialClass"로부터 상속받은 "PlanetClass"클래스를 가지고있다. 내 질문은 내 "PlanetClass"개체를 릴리스 할 때 두 dealloc 메서드를 통과하여 먼저 Planet 개체를 릴리스 한 다음 Celestial 개체를 릴리스하는 것입니다. 나는 iVar "bodyName"을 릴리스 할 수 있도록 천체에 dealloc을 추가했습니다.이 권한이 있다고 생각합니다. 확인하고 싶었습니까?상속 출시 명령?
@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
환호 -gary-
무엇을 어떻게하는가의 dealloc을 호출 지구 클래스의 인스턴스입니다
"Celestial"[super dealloc]도 부모 NSObject도 궁극적으로 할당 해제합니까? 아니면 다른 방식으로 작동합니까? – fuzzygoat
예. 모든 서브 클래스가 훌륭하게 동작하고 dealloc의 끝에서 [super dealloc]을 호출하면 NSObject는 dealloc 메서드를 호출합니다. – bobDevil