3

UPDATED

Why NSData dataWithContentsOfFile line is showing leak in Instruments? I am using ARC. Deployment Target is iOS 5.0

@autoreleasepool
{
    AudioPlayerAV *context = [userInfo valueForKey:@"self"];
    NSString *filepath = [userInfo valueForKey:@"filepath"];
    [context.player stop];

    //check if file is there fetch player from dict
    AVAudioPlayer *_player = nil;
    NSError *error = nil;
    NSData *filedata = [NSData dataWithContentsOfFile:filepath];

    _player = [[AVAudioPlayer alloc]initWithData:filedata error:&error]; 
    context.player = _player;
    NSLog(@"loadAndPlay error : %@",[error description]);
    context.player.numberOfLoops = (context.loop)?-1:0;
    context.player.volume = context.volume;
    [context.player play];
}
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
Saurabh Passolia
  • 8,099
  • 1
  • 26
  • 41

1 Answers1

2

Sometimes, instruments points to the wrong line, I think it is this leak in AVAudioPlayer.

from: Leak from NSURL and AVAudioPlayer using ARC

Looks to be a leak in Apple's code... I tried using both

-[AVAudioPlayer initWithData:error:] and -[AVAudioPlayer initWithContentsOfURL:error:]

In the first case, the allocated AVAudioPlayer instance retains the passed in NSData. In the second, the passed in NSURL is retained.

You can see the AVAudioPlayer object then creates a C++ object AVAudioPlayerCpp, which retains the NSData again

Later, when the AVAudioPlayer object is released, the NSData is released, but there's never a release call from the associated AVAudioPlayerCpp... (You can tell from the attached image)

Check it out, there are some instruments screenshots attached in the answer.

Community
  • 1
  • 1
Tieme
  • 62,602
  • 20
  • 102
  • 156