gpt4 book ai didi

iphone - NSData dataWithContentsOfFile 仪器 100% 泄漏

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:46:08 25 4
gpt4 key购买 nike

已更新

为什么 NSData dataWithContentsOfFile 行在 Instruments 中显示泄漏?我正在使用 ARC。部署目标是 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];
}

最佳答案

有时候,仪器会指向错误的线路,我认为是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 中附有一些仪器截图.

关于iphone - NSData dataWithContentsOfFile 仪器 100% 泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14084796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com