views:

70

answers:

1

Hi, I have the following code, that leaks in instruments when running in simulator ( memomry allocation is stable though) and is fine on the device. The code gets called everytime a button gets pressed.

Im a newbie - so any help and comments welcome :-)

if ( audioPlayer){
    if ( [audioPlayer isPlaying] ) {
        [audioPlayer stop];
        audioPlayer.delegate=nil;
    }
    [audioPlayer release];    
    audioPlayer = nil;      
}

audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:&error];

audioPlayer.numberOfLoops = 0;
audioPlayer.delegate = self;
[audioPlayer play];
+1  A: 

Check this tutorial on how to avoid memory leaks with AVAudioPlayer.

ibeitia
+1 for the link
TechZen