+ imageNamed : dealloc로 만든 이미지를 출시하려고 할 때 앱이 중단되는 이유는 무엇입니까? 다음과 같이 내 코드 :+ imageNamed로 만든 uiimage가 충돌 할 때 : dealloc에서 해제되었습니다.
에서 MyClass.h :
#import <UIKit/UIKit.h>
@interface MyClass{
UIImage *_thumbImage;
}
@property (nonatomic,retain) UIImage *thumbImage;
@end
MyClass.m :
#import "MyClass.h"
@implementation MyClass
@synthesize thumbImage = _thumbImage;
-(void)viewDidLoad{
[super viewDidLoad];
self.thumbImage = [UIImage imagedNamed:@"myImage.png""];
}
-(void)viewDidUnload{
self.thumbImage = nil;
}
-(void)dealloc{
[super dealloc];
[_thumbImage release]; //if i leave this here, the app crashes. should i release my property?
}
@end
그게 효과가 있어요. dealloc 메소드의 끝에서 [super dealloc]을 항상 호출해야합니까? 난 슈퍼 dealloc 그냥 부모 클래스에서 인스턴스 변수를 제거 생각, 내 하위 클래스에 ivars의 보유 개수에 영향을 미칠까요? – prostock
[super dealloc]은 인스턴스 변수의 보유 수를 변경하지 않습니다. 그것은 개체의 메모리를 해제 할 수 OS 알려줍니다. 그 후에 인스턴스 변수에 액세스하려고하면 더 이상 소유하지 않는 메모리를 참조하게됩니다. – cduhn
... 예. 항상 [super dealloc]에게 전화하십시오. – cduhn