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

simplymuzik3

macrumors 6502a
Original poster
Jan 29, 2009
590
1
Here is my code:
Code:
- (void) playclick {
	NSString *path = [[NSBundle mainBundle] pathForResource:@"MouseClickLoud" ofType:@"wav"];
	AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	theAudio.delegate = self;
	[theAudio play];
}
As you can see, AVAudioPlayer is allocated some memory, but it's never released. How would I dealloc the memory after it has finished playing? Thanks.

EDIT: Would this work?
Code:
 - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)theAudio successfully:(BOOL)flag {
	[theAudio release];
}

if you alloc theAudio, can you just use theAudio release? When I try theAudio dealloc, it crashes. Any help would be greatly appreciated! Thanks! :D
 
Yep, looks like it would work (I haven't read the docs though).

Don't ever call dealloc. That gets called automatically when the retain count is 0. Just use release.
 
Yep, looks like it would work (I haven't read the docs though).

Don't ever call dealloc. That gets called automatically when the retain count is 0. Just use release.

Okay, thanks so much! I think it worked because now the audio works perfectly all the time!! :D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.