AudioToolbox 库 AVAudioPlayer 中的内存泄漏

发布于 2024-10-16 16:25:50 字数 828 浏览 6 评论 0原文

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

Is there a memory lead issue with the AVAudioPlayer object? I'm getting a memory leak when using AVAudioPlayer in the simulator. It doesn't matter how I created the AVAudioPlayer. I've used initWithContentsOfURL and InitWithData. Below is a snippet of the code. Full project @ 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];

However there is no memory leak when testing it on the device. This issue is starting to leaning towards issue with the AudioToolBox library, but just want to confirm it with stackoverflow folks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光倒影 2024-10-23 16:25:50

使用 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

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

I am getting the same memory leak when using AVAudioPlayer. I have seen a few posts about similar occurrences of this leak with the AVAudioPlayer and VideoPlayer libraries around the web. It appears to be a problem with the library itself (blame 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

Edit: Also seeing the leak disappear when the target is run on the device.

因为看清所以看轻 2024-10-23 16:25:50

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

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

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

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

Just ran a test as I was experiencing the same issue. Instruments showed a leak at the start of an app when sound was played using AVAudioPlayer. It was only registered once at the start. The sounds generated afterwards have not had any further leaks.

When I ran the same app build on my iPhone using Instruments, there was no leak at all.

I'm running iOS 11.2.5 and Xcode Deployment Target is 11.0

Looks like it is just an Xcode bug but could be related to MacOS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文