I am stuck in some strange memory leak problem related to AVAudioPlayer and I need help after you have tried everything that comes to mind.
Here is a brief description of the problem - the code appears immediately after. I initialize my player and start playing the soundtrack in an infinite loop (and an infinite loop or single play did not change the problem). A few seconds after the start of the music, I switched to another sound track, so I create a new player, initialize him, release the old one (which plays), and then set the new one in its place and play it.
At this point in time (right after calling a new player - [Player play]) I get a memory leak (3.5Kb).
I tried the following:
Stop the old player and then release it - no effect
Release the player immediately after the playback instruction - did not start playback
Issue of twice old player - accident
A memory leak does NOT occur when I create and play the first player!
In addition, in the link, he says that “play” is asynchronous, and therefore, probably, it increases the number of links by 1, but in this case why [Player stop] does not help?
Thanks,
Here are some parts of the code on how I use it:
- (void) loadAndActivateAudioFunction { NSBundle *mainBundle = [NSBundle mainBundle]; NSError *error; NSURL *audioURL = [NSURL fileURLWithPath:[mainBundle pathForResource: Name ofType: Type]]; AVAudioPlayer *player = [(AVAudioPlayer*) [AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&error]; if (!player) { DebugLog(@"Audio Load Error: no Player: %@", [error localizedDescription]); DuringAudioPrep = false; return; } [self lock]; [self setAudioPlayer: player]; [self ActivateAudioFunction]; [self unlock];
}
- (void) setAudioPlayer : (AVAudioPlayer *) player { if (Player) { if ([Player isPlaying] || Repeat)
}
- (void) ActivateAudioFunction { [Player setVolume: Volume]; [Player setNumberOfLoops: Repeat]; [Player play]; DuringAudioPrep = false;
}
memory memory-leaks xcode avaudioplayer
Adi
source share