AVAudioPlayer Memory Leak - Media Player Framework

我的梦境 提交于 2019-12-18 05:11:36

问题


I am using AVAudioPlayer object to play an audio. I created an audioPlayer object initially. I play an animation and when ever animation starts I play the audio and pause the audio when the animation is finished. I initially found three memory Leaks using Instruments. (The responsible caller mentioned was RegisterEmbedCodecs). After suggestion from a "ahmet emrah" in this forum to add MediaPlayer framework, the number of leaks reduced to one. And is there any way to completely get rid of it?

Thanks and regards, krishnan.


回答1:


I got this problem resolved. This occured only in Simulator and not in the device.




回答2:


You may want to post some code up. This is typically how I play an audio file and I do not have any leaks appearing:

NSString *path = [[NSBundle mainBundle] pathForResource:@"somefile" ofType:@"mp3"];  

AVAudioPlayer * newAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];  
self.theAudio = newAudio; // automatically retain audio and dealloc old file if new file is loaded

[newAudio release]; // release the audio safely

theAudio.delegate = self; 
[theAudio prepareToPlay];
[theAudio setNumberOfLoops:0];
[theAudio play];


来源:https://stackoverflow.com/questions/2840637/avaudioplayer-memory-leak-media-player-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!