When calling AudioServicesPlaySystemSound, it plays well the previous created SystemSound. But when i call AudioServicesDisposeSystemSoundID directly afterwards, the sound is not played. It seems as the Sound-Resource is disposed before it would have been played.
But on this Stackoverflow-Question the people say, that it is necessary to dispose the System-Sound to avoid memory leaks.
How is the correct way for both methods? Shall i call the Dispose-Method with a timer some seconds later? Or create a singleton which creates the Sound-Resource once at the first call of the Play-Method and dispose the Resource at dealloc of the singleton?
- (void) playSound {
NSURL *url = [[NSBundle mainBundle] URLForResource: @"SentMessage"
withExtension: @"wav"];
SystemSoundID mBeep;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &mBeep );
AudioServicesPlaySystemSound(mBeep);
AudioServicesDisposeSystemSoundID(mBeep);
}