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 hilarioussoundboar开发者_开发技巧dipViewController
-(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//
}
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.
Have you ever called "AudioServicesDisposeSystemSoundID" to free the soundID you've created in your code?
精彩评论