how to solve memory leaks in AVAudioPlayer-iphonesdk
how to solve memory leaks in AVAudioPlayer-iphonesdk. here. i will give the my code.. memory leaks are in my code, how to solve it..
.h file
AVAudioPlayer *titlescreenaud;
.m file
titlescreenaud=[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"TitleScreen_BgmAudio" ofType:@"mp3"]] error:NULL];//***Memory leaks on here......***
titlescreenaud.numberOfLoops=-1;
[titlescreenaud play];
After finish the sound
-(void)finish
{
[titlescreenaud stop];
开发者_StackOverflow [titlescreenaud release];
titlescreenaud=nil;
}
how to release the avaudioplayer please help me.......
titlescreenaud=[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"TitleScreen_BgmAudio" ofType:@"mp3"]] error:NULL];//***Memory leaks on here......***
I assume Instruments is indicating that the memory leak is there. What it means is that something allocated on that line has not been released. The actual leak may be elsewhere and will most likely be because of a missing release
.
Is your finish
method really being called? Do you release
titlescreenaud
in dealloc
?
There isn't enough code here to be able to specifically pinpoint the problem.
If you are allocating AVAudioPlayer object in ViewDidLoad than you will not face the problem. But if you are calling methods repeatatively and in which you have allocated the object than it is always going to allocate the memory for the same object. You can check the retainCount before releasing the memory.
精彩评论