I created a singleton with contains an AVAudioPlayer object
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
@interface drwAudioPlayer : NSObject <AVAudioPlayerDelegate>
@property AVAudioPlayer *aPlayer;
+(drwAudioPlayer *) sharedPlayer {
static drwAudioPlayer *sharedPlayer = nil;
if (!sharedPlayer) {
sharedPlayer = [[super allocWithZone:nil] init];
}
return sharedPlayer;
}
-(void) setPlayerEpisode:(NSData *) episodeFile {
NSError *error;
aPlayer = nil;
aPlayer = [[AVAudioPlayer alloc] initWithData:episodeFile error:&error];
}
In my main view I included the above class and created an object of type drwAudioPlayer. When I call [drwAudioPlayer.aPlayer setPlayerEpisode:foo]
, I see that the new file is getting loaded and the old one released.
But as soon as I start the playback of a file and then try to call [drwAudioPlayer.aPlayer setPlayerEpisode:foo2]
the memory increases by the size of the new file being loaded.
What do I have to do to basically free up the memory before loading the new file to play.
I'm using ARC.