AudioToolbox 库 AVAudioPlayer 中的内存泄漏

doc*_*ang 3 memory-leaks avaudioplayer audiotoolbox

AVAudioPlayer 对象是否存在内存引导问题?在模拟器中使用 AVAudioPlayer 时出现内存泄漏。我如何创建 AVAudioPlayer 并不重要。我用过initWithContentsOfURLInitWithData。下面是代码的一个片段。完整项目@ Github https://github.com/docchang/MemoryLeakAVAudioPlayer

NSError *error;
NSURL *playerURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Bell" ofType:@"m4a"]];   
self.playerWithURL = [[AVAudioPlayer alloc] initWithContentsOfURL:playerURL error:&error];
if (!playerWithURL) {
    NSLog(@"no %@.%@: %@",@"Introduction2", @"m4a", [error localizedDescription]);  
}
playerWithURL.volume = 0.9f;
playerWithURL.numberOfLoops = 0;
[playerWithURL play];
Run Code Online (Sandbox Code Playgroud)

但是在设备上测试时没有内存泄漏。这个问题开始倾向于 AudioToolBox 库的问题,但只是想与 stackoverflow 的人确认一下。

mja*_*ama 5

使用 AVAudioPlayer 时出现相同的内存泄漏。我在网上看到了一些关于 AVAudioPlayer 和 VideoPlayer 库发生类似泄漏的帖子。似乎是库本身的问题(怪苹果):

  1. iPhone:OpenAL 和 AudioToolbox 泄漏
  2. https://appcelerator.lighthouseapp.com/projects/32238/tickets/1992-ios-strange-behavior-and-intermittant-mem-leak-on-embedded-video-test-case

编辑:当目标在设备上运行时,也会看到泄漏消失。