AudioToolbox库AVAudioPlayer中的内存泄漏

时间:2011-02-06 19:29:26

标签: 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];

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

2 个答案:

答案 0 :(得分:3)

使用AVAudioPlayer时,我遇到了相同的内存泄漏。我在Web上看到了一些关于这种泄漏与AVAudioPlayer和VideoPlayer库发生类似事件的帖子。这似乎是图书馆本身的一个问题(责怪Apple):

  1. iPhone: OpenAL & AudioToolbox leak
  2. https://appcelerator.lighthouseapp.com/projects/32238/tickets/1992-ios-strange-behavior-and-intermittant-mem-leak-on-embedded-video-test-case
  3. 编辑:当设备上运行目标时,也会看到泄漏消失。

答案 1 :(得分:0)

刚刚遇到同样的问题,我刚刚进行了测试。当使用AVAudioPlayer播放声音时,乐器在应用程序启动时显示泄漏。它只在开始时注册了一次。之后产生的声音没有任何进一步的泄漏。

当我使用Instruments在我的iPhone上运行相同的应用程序时,根本没有泄漏。

我正在运行iOS 11.2.5并且Xcode部署目标是11.0

看起来它只是一个Xcode错误,但可能与M​​acOS有关。

相关问题