AudioToolbox 库 AVAudioPlayer 中的内存泄漏
AVAudioPlayer 对象是否存在内存问题?在模拟器中使用 AVAudioPlayer 时出现内存泄漏。我如何创建 AVAudioPlayer 并不重要。我使用了 initWithContentsOfURL
和 InitWithData
。下面是代码片段。完整项目@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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 AVAudioPlayer 时我遇到了同样的内存泄漏。我在网络上看到过一些关于 AVAudioPlayer 和 VideoPlayer 库发生类似泄漏的帖子。这似乎是库本身的问题(归咎于苹果):
编辑:当目标在设备上运行时,还会看到泄漏消失。
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):
Edit: Also seeing the leak disappear when the target is run on the device.
刚刚进行了测试,因为我遇到了同样的问题。当使用 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.