我试图将background.mp3文件作为我的游戏播放文件播放,它运行正常 但它泄漏了记忆
@interface slots2ViewController : UIViewController <AVAudioPlayerDelegate>
{
AVAudioPlayer *PlayBack;
}
@property(nonatomic, retain) AVAudioPlayer *PlayBack ;
.m文件
@synthesize PlayBack;
-(void)LoadnPlaySound
{
NSString *SubDir = [NSString stringWithFormat:@"AudioFiles/Theme%d",SlotId];
NSURL* file_url2 = nil;
file_url2 = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"background"ofType:@"mp3" inDirectory:SubDir ]];
AVAudioPlayer* TmpPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:file_url2 error:nil];
self.PlayBack = TmpPlayer;
self.PlayBack.delegate = self;
[TmpPlayer release];
[self.PlayBack prepareToPlay];
[self.PlayBack play];
[release file_url2];
}
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)ThePlayer successfully:(BOOL)flag
{
[self.PlayBack play];
}
内存泄漏仪表说[self.PlayBack prepareToPlay]是100%泄漏点
每当我改变主题时,我都会调用LoadnPlaySound。
我也需要释放self.PlayBack,如果是,那么