@implementation MyClass
-(id) init
{
NSString *path0 = [ [NSBundle mainBundle] pathForResource:@"myfile" ofType:@"m4a" ];
mSound = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path0] error:NULL];
mSound.delegate = self;
}
-(void) release
{
mSound.delegate = nil; //<- this line causes MyClass release function to be called recursively
[ mSound release ]; //<- removing the line above makes this line do the same, i.e. calls myclass release recursively
}
AvAudioPlayer를 해제하면 델리게이트 개체도 해제되는 것 같습니다. 델리게이트에 할당 할 때 수동으로 retain을 호출하려고했지만 도움이되지 않았습니다. 세드릭 내가 전무AvAudioPlayer에서 delegate를 nil로 설정하면 위임 객체가 해제됩니까?
어떤 생각에 대리자를 할당 할 때 바로 초기화에서
-(id) init
{
NSString *path0 = [ [NSBundle mainBundle] pathForResource:@"myfile" ofType:@"m4a" ];
mSound = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path0] error:NULL];
mSound.delegate = self;
mSound.delegate = nil; //<- (just for test), causes MyClass release to be invoked,
}
내가 MyClass에의 방출을 얻을를 호출하는 : 내가 좋아하는 뭔가를 할 경우에도
?
이것이 문제의 해결책은 아니지만 'release'와'dealloc'을 섞어서 사용했습니다. 인스턴스 변수를 해제하는 것은'dealloc'에서 이루어져야합니다. –