문제

I'm new to playing sounds on iOS. I know that to play various sounds I should have a audio manager helper class keeping all the audios together.

Now, I'm wondering if it is OK to do this without memory leak:

AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&err];
[newPlayer play];

Will the player get released after it finished playing? Or do I need to keep a pointer to it, call [newPlayer stop] when it finishes, then set the pointer to nil?

도움이 되었습니까?

해결책

Actually it is the opposite of a leak. If you do not retain the player, it will be released immediately and will never play.

See my answer here for more info: Playing back audio using AVAudioPlayer iOS 7

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top