2012-12-29 2 views
2

ОБНОВЛЕНО

Почему NSData dataWithContentsOfFile линия показывает утечку в инструменты? Я использую ARC. Цель развертывания является IOS 5,0NSData 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

@ Атиф, конечно, это не так, но это создает утечку, но живые байты увеличиваются с каждой утечкой. – samfisher

ответ

1

Иногда инструменты указывает на неправильную линию, я думаю, что это this утечка в AVAudioPlayer.

от: 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.

Смежные вопросы