Question is in the title: "Do I need to release SystemSoundID if I have ARC on?" Here is my Code:
NSURL *pathURL = [NSURL fileURLWithPath:path];
SystemSoundID soundid;
AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)pathURL, &soundid);
AudioServicesPlaySystemSound(soundid);
And if so, when do I release it? (I don't have a dealloc method because I'm using a static method and that cannot be changed)
Also, is this currently the best way to play a sound effect I heard this framework is now deprecated.
THANKS!
Yes, you do need to release it. ARC only concerns itself with Obj-C objects, and a SystemSoundID
is not an obj-c object. At some point you do need to call AudioServicesDisposeSystemSoundID()
on your SystemSoundID
value. You could do this with a system sound completion routine (using AudioServicesAddSystemSoundCompletion()
).
As for what sergio is talking about, you're leaking the pathURL
object. You've used __bridge_retained
, which transfers ownership of the object to CoreFoundation. You should probably just change that to (__bridge CFURLRef)pathURL
, which will not transfer ownership. The AudioServices API will retain the object as necessary.