开发者

AVAudioPlayer is leaking, where should i release it??

开发者 https://www.devze.com 2023-03-23 18:02 出处:网络
i m trying to play background.mp3 files as my game playback file ,and it works fine but it leaking memory

i m trying to play background.mp3 files as my game playback file ,and it works fine but it leaking memory

@interface slots2ViewController : UIViewController <AVAudioPlayerDelegate>
{
 AVAudioPlayer *PlayBack;
}
@property(nonatomic, retain) AVAudioPlayer *PlayBack ;

.m file

@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.delegat开发者_如何学Goe = self;
[TmpPlayer release];
[self.PlayBack prepareToPlay];
[self.PlayBack play];
  [release file_url2];

}


-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)ThePlayer successfully:(BOOL)flag
 {
   [self.PlayBack play];
 }

memory leak instrument says [self.PlayBack prepareToPlay] is the point of 100% leak i m calling LoadnPlaySound whenever i m changing the theme. also do i need to release self.PlayBack if yes then where

0

精彩评论

暂无评论...
验证码 换一张
取 消