0
@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設置委託以釋放委託對象?
即使我做這樣的事情:
-(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'中完成。 – 2009-10-09 17:49:21