【问题标题】:memory leak in AudioToolbox library AVAudioPlayerAudioToolbox 库 AVAudioPlayer 中的内存泄漏
【发布时间】:2011-02-06 19:29:25
【问题描述】:

AVAudioPlayer 对象是否存在内存引导问题?在模拟器中使用 AVAudioPlayer 时出现内存泄漏。我如何创建 AVAudioPlayer 并不重要。我用过initWithContentsOfURLInitWithData。下面是代码的sn-p。完整项目@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 人员确认一下。

【问题讨论】:

    标签: memory-leaks avaudioplayer audiotoolbox


    【解决方案1】:

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

    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

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

    【讨论】:

      【解决方案2】:

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

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-11-24
        • 1970-01-01
        • 2011-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多