2012-12-29 80 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一些儀器截圖。