Help Dealloc with Audio

Discussion in 'iOS Programming' started by simplymuzik3, Jul 17, 2009.

  1. simplymuzik3 macrumors 6502a

    Jan 29, 2009
    Here is my 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?
     - (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
  2. kainjow Moderator emeritus


    Jun 15, 2000
    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.
  3. simplymuzik3 thread starter macrumors 6502a

    Jan 29, 2009
    Okay, thanks so much! I think it worked because now the audio works perfectly all the time!! :D

Share This Page