AVAudioPlayer Memory Leak - Media Player Framework

I am using an AVAudioPlayer object to play sound. First I created an audioPlayer object. I play the animation, and when the animation starts, I play the audio and pause the sound when the animation is finished. I originally discovered three memory leaks with tools. (The responsible caller was RegisterEmbedCodecs). After the "ahmet emrah" sentence in this forum, to add MediaPlayer, the number of leaks was reduced to one. And is there a way to completely get rid of it?

Thanks and greetings, Krishnan.

+3
source share
2 answers

. , .

+2

, . , :

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];
0

Source: https://habr.com/ru/post/1745574/


All Articles