Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

midntdj

macrumors newbie
Original poster
Sep 23, 2009
9
0
I just started to use CLANG to help find any leaks with in my code. I have a some code that CLANG shows a potential leak, but I'm not sure what I need to do to resolve it. Any help would be greatly appreciated (assuming there is something wrong with how I implemented the audio).

I'm not sure that this is truly a leak or just a warning that CLANG doesn't like. In either case, I want to clean up my code so there are no warnings or potential leaks.

Here is the code that has the potential leak (baseURL is what CLANG is complaining about):
Code:
	id sndpath = [[NSBundle mainBundle] pathForResource:@"Select" ofType:@"caf" inDirectory:@"/"];
	CFURLRef baseURL = (CFURLRef)[[NSURL alloc] initFileURLWithPath:sndpath];

	AudioServicesCreateSystemSoundID (baseURL, &btnTouchID);

This is called in my viewDidLoad routine to set up the sound when a button is touched.

In te dealloc routine I do dispose of the btnTouchID.

Is there a better way to define your SoundID?

Thanks.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
You're creating baseURL but not releasing it in that method, which is why Clang is complaining. Either release it manually, autorelease it, or use the autorelease convenience method instead:

Code:
CFURLRef baseURL = (CFURLRef)[NSURL fileURLWithPath:sndpath];
 

midntdj

macrumors newbie
Original poster
Sep 23, 2009
9
0
use the autorelease convenience method instead:

Code:
CFURLRef baseURL = (CFURLRef)[NSURL fileURLWithPath:sndpath];

Thanks kainjow for your help. The autorelease convenience method you listed, corrected the CLANG warning. I had tried earlier to manually releasing the method, but CLANG still gave me the warning.

By changing the intifileURLWithPath to use fileURLWithPath seems to be the better solution.

Thank you again.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.