@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 on self を手動で呼び出そうとしましたが、役に立ちませんでした。
私が次のようなことをしても:
-(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,
}
デリゲートを nil に割り当てると、初期化からすぐに呼び出されるように Myclass のリリースを取得します
何が起こっているのですか?