简体   繁体   中英

memory leak in objective-c xcode code

I am getting an analyser error showing a potential leak in the following code:

- (void)viewDidLoad {
[super viewDidLoad];
mAngle = 0.0;
cligneBool = YES;

SoundManager *mSoundManager = [[SoundManager alloc] init];
[mSoundManager initOpenAL];
[mSoundManager loadSound:[[NSBundle mainBundle] pathForResource:@"bing.wav" ofType:nil] SoundKey:@"bing"];
[mSoundManager loadSound:[[NSBundle mainBundle] pathForResource:@"ding.wav" ofType:nil] SoundKey:@"ding"];
[mSoundManager loadSound:[[NSBundle mainBundle] pathForResource:@"click.wav" ofType:nil] SoundKey:@"click"];
[mSoundManager loadSound:[[NSBundle mainBundle] pathForResource:@"die.wav" ofType:nil] SoundKey:@"die"];
[mSoundManager loadSound:[[NSBundle mainBundle] pathForResource:@"kaboom.wav" ofType:nil] SoundKey:@"kaboom"];
[mSoundManager loadMusic:@"Musique - Finale.mp3" MusicKey:@"intro"];
[mSoundManager loadMusic:@"game_music01.wav" MusicKey:@"game01"];

[mSoundManager playMusic:@"intro" Loops:YES];

NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
NSString *volume = (NSString *)[userDefault objectForKey:@"volume"];
sunAnimate.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);

if(volume == nil) {
    [userDefault setValue:@"1.0" forKey:@"volume"];
} else {
    float mVolume = [volume floatValue];
    [mSoundManager setMusicVolume:mVolume];
}

[self sunTurn];

[NSTimer scheduledTimerWithTimeInterval:3.10 target:self selector:@selector(cligne) userInfo:nil repeats:YES];
}

在此处输入图片说明

Can anyone see the problem with the above set of code?

This is my last error in the app code, so any help clearing this one would be appreciated!

Thanks!

I guess you are not using ARC, if that is the case you are not releasing mSoundManager.

Either use ARC (Best choice) or release mSoundManager (Not so good choice).

Here is what you get by clicking on the right blue indicator: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM