Question

It's a seemingly simple API. I thought that I was incorrectly releasing the AVAudioRecorder object altogether, but even after eliminating that concern, I'm still getting a leak reported.

Here's are the four methods I use to handle recording:

-(void) startRecording {

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:&err];
[[AVAudioSession sharedInstance] setActive:YES error:nil];

NSError *err;
err = nil;

AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:audioFileURL settings:nil error:&err];

//show user an error on fail
if (!recorder) {
        NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:[err localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
        return;
}

[recorder prepareToRecord];
recorder.delegate = self;
recorder.meteringEnabled = NO;

self.isRecording = YES;
[self colorRecordingLight];
[self toggleButtons:3];

[recorder record];

self.audioRecorder = recorder;
[recorder release];

}

-(void) stopRecording {

[audioRecorder stop];
[self cleanupPostRecording];


}

-(void) audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag {

//if this page didn't have audio before, it does now.
self.hasAudio = YES;
[self cleanupPostRecording];

}

-(void) cleanupPostRecording {

[[AVAudioSession sharedInstance] setActive:NO error:nil];

self.isRecording = NO;
[self setAudioRecorder:nil];
[self toggleButtons:4];
[self colorRecordingLight];



}

I get multiple leaks (when running on the device):

Leaked Object   #   Address Size    Responsible Library Responsible Frame
NSCFDictionary      0x16dc20    64  AVFoundation    prepareToRecordQueue(AVAudioRecorder*, AudioRecorderImpl*)
GeneralBlock-32     0x16cf00    32  AVFoundation    prepareToRecordQueue(AVAudioRecorder*, AudioRecorderImpl*)
NSCFNumber      0x160f30    16  Foundation  -[NSPlaceholderNumber initWithUnsignedInteger:]

Leaks tells me that the call I'm making that is 100% responsible is [recorder prepareToRecord];

Anyone seen this or could give me an insight?

Was it helpful?

Solution

I was able to eliminate this leak.

In the code I originally posted, I generated an NSURL from an NSString and stored that in a property.

Each time I allocated an AVAudioRecorder, I passed it this NSURL directly from the property.

By storing my file location as an NSString instance variable and then creating a new NSURL each time from that string and passing this fresh NSURL to my newly allocated AVAudioRecorder, it works and does not produce these leaks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top