2012-12-29 53 views
2

修订

为什么NSData dataWithContentsOfFile线表示仪器泄漏? 我正在使用ARC。部署目标是iOS的5.0在仪器的NSData dataWithContentsOfFile 100%泄漏

@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]; 
} 
+0

100%分配或100%泄漏?这不意味着此时分配的增加是由该对象引起的100%吗? – Atif

+0

和'dataWithContentsOfFile'返回一个'autoreleased'对象。它不应该是一个泄漏 – Atif

+0

@Atif当然它不会但是这是造成泄漏,但活的字节数随着每次泄漏而增加。 – samfisher

回答

1

有时候,仪器指向错误的路线,我认为这是AVAudioPlayerthis泄漏。

来自: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)

检查出来,也有附加在answer一些仪器截图。