CDAudioManager Memory Leak

Forums Programming sound engine: CocosDenshion et al CDAudioManager Memory Leak

This topic contains 4 replies, has 4 voices, and was last updated by  Birkemose 1 year, 3 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
Author Posts
Author Posts
October 25, 2012 at 5:45 am #244968

slhertz
Participant
@slhertz

Hi,

I am profiling my game for memory leaks, and there are a few memory leaks caused by the following code in CDAudioManager.m after my code calls preloadBackgroundMusic on the SimpleAudioEngine singleton.

-(void) load:(NSString*) filePath {
//We have alread loaded a file previously, check if we are being asked to load the same file
if (state == kLAS_Init || ![filePath isEqualToString:audioSourceFilePath]) {
CDLOGINFO(@"Denshion::CDLongAudioSource - Loading new audio source %@",filePath);
//New file
if (state != kLAS_Init) {
[audioSourceFilePath release];//Release old file path
[audioSourcePlayer release];//Release old AVAudioPlayer, they can't be reused
}
audioSourceFilePath = [filePath copy];
NSError *error = nil;
NSString *path = [CDUtilities fullPathFromRelativePath:audioSourceFilePath];
//LEAK audioSourcePlayer = [(AVAudioPlayer*)[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
if (error == nil) {
[audioSourcePlayer prepareToPlay];
audioSourcePlayer.delegate = self;
if (delegate && [delegate respondsToSelector:@selector(cdAudioSourceFileDidChange:)]) {
//Tell our delegate the file has changed
[delegate cdAudioSourceFileDidChange:self];
}
} else {
CDLOG(@"Denshion::CDLongAudioSource - Error initialising audio player: %@",error);
}
} else {
//Same file - just return it to a consistent state
[self pause];
[self rewind];
}
audioSourcePlayer.volume = volume;
audioSourcePlayer.numberOfLoops = numberOfLoops;
state = kLAS_Loaded;
}

More specifically, it seems that the leak occurs due to

[NSURL fileURLWithPath:path]

The NSURL object should be autoreleased, but perhaps there is a bug in the Objective-C libraries?

I am using cocos2d 2.0.

Thanks,

Sam

October 26, 2012 at 2:51 pm #390802

Liquidsoul
@liquidsoul

Hi,

Do you use ARC in your project ?

Liquidsoul

November 10, 2012 at 2:38 am #390803

slhertz
Participant
@slhertz

I do not use ARC.

January 16, 2013 at 5:17 pm #390804

macgeo
Participant
@macgeo

Having same issue. I just switched to using ARC in hopes that it would solve problem but it didn’t. Might be that I excluded the cocos2d stuff from ARC under compile settings.

@slhertz did you have any luck with this issue?

January 16, 2013 at 5:40 pm #390805

Birkemose
Keymaster
@birkemose

If your app leaks less than 1MB / day, thou shall not worry.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.