When I use AudioToolBox for playing music, memory leaks heavily.
AVAudioPlayer *newMusicPlayer = [[AVAudioPlayer alloc] initWithData:data error:&error];
Maybe you did better than me and I haven't the XCode in my front, but :
object created, reference created:
AVAudioPlayer *newMusicPlayer = [[AVAudioPlayer alloc] initWithData:data error:&error];
it is assignment and not allocation, no retain:
_musicPlayer = newMusicPlayer;
out of function playMusicWithMusicData
it would deallocate the newMusicPlayer
and it would crash my code in other function when I use the _musicPlayer
. The analyzer tool nagged so much as I made a retain, maybe a release too.
if you are using ios4, than isn't ARC this project.
in if branch:
[_musicPlayer stop];
_musicPlayer = nil;
I would check the _musicPlayer
to not be nil, but that will not solve your problems.
No clue where it could be, if not in ios and probably there it will be:
Did solve if you change the delegate instead of self.
_musicPlayer.delegate = self;
to any other class?