user1513914
user1513914

Reputation: 1

Fixing memory leaks in my first app

People of the Stack Overflow I need your help. I am about to publish my first app ever to the App Store and I need help fixing the memory leaks my app has. Its a simple view based application with multiple views, iAds, and buttons with sounds (The app is a simple sound board).I would need examples of what exactly I should put and a picture of where

Analyzer message: Potential Leak of an Object allocated on Line 135 and stored into 'soundFileURLRef'

-(IBAction)sound25 {
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"BELLMACH", CFSTR ("wav"), NULL);

    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);
} 

Upvotes: 0

Views: 128

Answers (2)

Hot Licks
Hot Licks

Reputation: 47739

Since the name "CFBundleCopyResourceURL" contains the word "Copy", it follows the "create rule" and you "own" the object and are responsible for releasing it when you're done with it.

Upvotes: 0

Tim
Tim

Reputation: 60140

The documentation for CFBundleCopyResourceURL says that it follows the "Create Rule", which in turn basically says that any function with "create" or "copy" in its name returns a retained object. You have ownership of this object until you're done with it - it's therefore your responsibility to call CFRelease on the object when you have no further use for it. Presumably, that's after you use it to create and play a system sound, so you could just add

CFRelease(soundFileURLRef);

at the end of that method and be OK, assuming you don't hang on to or need soundFileURLRef for anywhere else.

Upvotes: 3

Related Questions