Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

PizzaTray

macrumors newbie
Original poster
Oct 31, 2009
25
0
Code:
- (void) playIt:(NSString*)sndTxt andType:(NSString*)sndType {
	
	NSString *path = [[NSBundle mainBundle] pathForResource:sndTxt ofType:sndType];
	theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	theAudio.delegate = self;
	[theAudio play];
}
Code:
[self playIt:@"button-30" andType:@"mp3"];

"Leaked Object:
GeneralBlock-304
AVAudioPlayer"

Anyone know how to free the leaks causes by the avPlayer?
 
Fix It :)

If someone has the same problem here is the code:

Code:
AVAudioPlayer*		 theAudio;
Code:
@property (nonatomic,retain) AVAudioPlayer* theAudio;
Code:
@synthesize theAudio;
Code:
- (void) playIt:(NSString*)sndTxt andType:(NSString*)sndType {
	
	NSString *path = [[NSBundle mainBundle] pathForResource:sndTxt ofType:sndType];
	
	self.theAudio = [AVAudioPlayer alloc];
	if([theAudio initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]) {
		[theAudio autorelease];
	}
	else {
		[theAudio release];
		theAudio = nil;
	}
	[self.theAudio setDelegate:self];
	
	[self.theAudio play];
}
Code:
- (void)dealloc {
	[self.theAudio stop];
	[self.theAudio release];
}

And now u've got 0 leaks :p
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.