1

Here is my Code(ARC enabled) where memory leak is seen.

Please help me to solve this issue.

- (void) setMusic
{      
     /*
     Initialise and set the music for the game.
     */

 NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"actionMusic" ofType:@"caf"]];
NSError *error = nil;
_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (!error)
{
    _audioPlayer.delegate = self;
    if(_musicFlag)
    {
        [_audioPlayer play];
    }
    [_audioPlayer setNumberOfLoops:INT32_MAX];
}

error = nil;
url =nil;

url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"pew" ofType:@"wav"]];
_moveMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

if (!error)
{
    _audioPlayer.delegate = self;
}

error = nil;
url =nil;


url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Won" ofType:@"wav"]];
_winningMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

if (!error)
{
    _winningMusic.delegate = self;
    [_winningMusic setNumberOfLoops:1];
}

}

Here is the detals of the leak enter image description here

Vinayak Kini
  • 2,919
  • 21
  • 35

1 Answers1

0

I found the answer for the leak.

This leak is due to AVAudioPlayer foundation class which is yet to be fixed by Apple.

Thus Usage of AVAudioPlayer foundation class leads to leaks.

Check This link for more detail

Community
  • 1
  • 1
Vinayak Kini
  • 2,919
  • 21
  • 35