3

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 的人确认一下。

4

2 回答 2

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

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

于 2011-02-24T09:26:17.647 回答
1

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

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

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

看起来这只是一个 Xcode 错误,但可能与 MacOS 有关。

于 2018-02-22T12:36:03.983 回答