我想釋放我爲AVAudioPlayer分配的內存,但是當我試圖釋放它時,聲音沒有播放。這是潛在的內存泄漏,我怎麼能擺脫這個。如何在下面的代碼中發佈AVAudioPlayer
這裏下面的代碼是用來挑選錯誤的選擇,然後我播放錯誤的聲音,如果我選擇多次錯誤選擇然後它被分配多次,那麼我怎麼能擺脫這一點。
else
{
NSString *[email protected]"Error.mp3";
NSError *error;
NSURL *urlString = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%s", [[NSBundle mainBundle] resourcePath],[soundName UTF8String]]];
AVAudioPlayer *worngAudioPlay = [[AVAudioPlayer alloc] initWithContentsOfURL:urlString error:&error];// here I also used to release using autorelease then not played sound
worngAudioPlay.delegate = self;
if (worngAudioPlay == nil)
{
}
else
{
[worngAudioPlay play];
}
// [worngAudioPlay release]; // Here I released then not played sound
}
謝謝, Madan Mohan。
嗨,但是當我停下來然後這個方法不會被調用。 – 2011-04-14 09:32:20
@馬丹莫漢閱讀文檔我不記得確切的方法名稱。你會發現在avaudioplayer類文檔 – 2011-04-14 09:56:14