AVAudioPlayer不释放内存 [英] AVAudioPlayer not releasing memory
问题描述
我初始化一个ivar AVAudioPlayer变量,播放并尝试释放它的内存。在释放线之后,它不会设置为0x0。在nil行之后,它不会改变为0x0。
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@mysoundofType:@aifinDirectory:@/]] error:& err]
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = .5;
[audioPlayer prepareToPlay];
[audioPlayer play];
[audioPlayer release];
audioPlayer = nil;
好吧,
AVAudioPLayer异步播放音频文件。您不应该在开始播放后释放播放器,它可能会导致一些与内存相关的错误,您的音频文件也可能无法播放。
您应该通过avaudioplayerdelegate 。有关详情,请查看此 answer 。
希望这有助于。
感谢,
Madhup
I initialize an ivar AVAudioPlayer variable, play and the try to release its memory. After the release line, it doesn't set to 0x0. After the nil line it doesn't change to 0x0. Does AVAudioPlayer require something special to release its memory?
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: @"mysound" ofType: @"aif" inDirectory:@"/"]] error: &err];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = .5;
[audioPlayer prepareToPlay];
[audioPlayer play];
[audioPlayer release];
audioPlayer = nil;
Well,
AVAudioPLayer plays the audio files asynchronously. You should not release the player after you start playing, it may lead to some memory related error and your audio file may not play too.
You should release the player via avaudioplayerdelegate. For more details you can check this answer too.
Hope this helps.
Thanks,
Madhup
这篇关于AVAudioPlayer不释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!