Xcode 音频内存泄漏?
我正在开发一个音板应用程序,当我分析我的应用程序时,它总是检测到内存泄漏。它在 iOS 模拟器上运行良好,但大多数声音在实际设备上不起作用。我认为这与内存泄漏有关。任何提示。这是代码。这只是所有代码的一小部分。我正在使用音频工具箱。抱歉,谢谢,我是一个非常新的初学者。
#import "hilarioussoundboardipViewController.h"
@implementation hilarioussoundboardipViewController
-(IBAction)sound2 {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound2", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID); //it says there is a potential memory leak here//
}
I'm working on a soundboard app, and when I analyze my app, it always detects memory leaks. It works fine on the iOS Simulator, but most sounds do not work on the actual device. I think it has to do with the memory leaks. Any tips. Here is the code. It's only a snippet of all of the code. I am using the AudioToolbox. Sorry, and thanks ahead, I am a very new beginner.
#import "hilarioussoundboardipViewController.h"
@implementation hilarioussoundboardipViewController
-(IBAction)sound2 {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound2", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID); //it says there is a potential memory leak here//
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下 来自 Apple 的示例代码。您可能会发现一些有关资源/内存泄漏的提示或有关如何让音频在物理设备上播放的提示。
Take a look at the example code from Apple. You might find some hints about resource/memory leaks or hints about how to get audio to play on the physical device.
您是否曾经调用过“AudioServicesDisposeSystemSoundID”来释放您在代码中创建的 soundID?
Have you ever called "AudioServicesDisposeSystemSoundID" to free the soundID you've created in your code?