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
SystemSoundIDis not an obj-c object. At some point you do need to callAudioServicesDisposeSystemSoundID()on yourSystemSoundIDvalue. You could do this with a system sound completion routine (usingAudioServicesAddSystemSoundCompletion()).As for what sergio is talking about, you’re leaking the
pathURLobject. 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.