内存泄漏问题

时间:2010-04-01 08:46:58

标签: iphone memory memory-management memory-leaks

抱歉,格式化代码难以在此处显示正确???

我试图理解从运行乐器中获得的读数 在我的应用程序上告诉我,我正在泄漏记忆。 事实上有很多,从内部报道 基金会,AVFoundation CoreGraphics等我认为我没有 控制,所以应该忽略如下:

Malloc 32字节:96字节,AVFoundation,prepareToRecordQueue

或 Malloc 128字节:128字节,CoreGraphics,open_handle_to_dylib_path

我是否正确假设系统将解决这些问题?

但是有报道说我相信我是泄密 负责,如:

此次调用报告此行泄漏2.31KB

[self createAVAudioRecorder:frameAudioFile];

紧接着就是:

-(NSError*) createAVAudioRecorder: (NSString *)fileName {     

    // flush recorder to start afresh 
    [audioRecorder release]; 
    audioRecorder = nil; 

    // delete existing file to ensure we have clean start 
    [self deleteFile: fileName]; 

    VariableStore *singleton = [VariableStore sharedInstance]; 

    // get full path to target file to create 
    NSString *destinationString = [singleton.docsPath stringByAppendingPathComponent: fileName]; 

    NSURL *destinationURL = [NSURL fileURLWithPath: destinationString]; 

    // configure the recording settings 
    NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:6];       //******  LEAKING 384 BYTES 

    [recordSettings setObject:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey: AVFormatIDKey];   //***** LEAKING 32 BYTES 

    float sampleRate = 44100.0; 
    [recordSettings setObject:[NSNumber numberWithFloat: sampleRate] forKey: AVSampleRateKey];   //***** LEAKING 48 BYTES 

    [recordSettings setObject:[NSNumber numberWithInt:2]  forKey:AVNumberOfChannelsKey]; 

    int bitDepth = 16; 
    [recordSettings setObject: [NSNumber numberWithInt:bitDepth] forKey:AVLinearPCMBitDepthKey];   //***** LEAKING 48 BYTES 

    [recordSettings setObject:[NSNumber numberWithBool:YES] forKey:AVLinearPCMIsBigEndianKey]; 

    [recordSettings setObject:[NSNumber numberWithBool: NO]forKey:AVLinearPCMIsFloatKey]; 

    NSError *recorderSetupError = nil; 

    // create the new recorder with target file 
    audioRecorder = [[AVAudioRecorder alloc] initWithURL: destinationURL settings: recordSettings error: &recorderSetupError];       //***** LEAKING 1.31KB 

    [recordSettings release]; 

    recordSettings = nil; 

    // check for erros 

    if (recorderSetupError) { 

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Can't record" message: [recorderSetupError localizedDescription] delegate: nil cancelButtonTitle: @"OK" otherButtonTitles: nil]; 

            [alert show]; 
            [alert release]; 

            alert = nil; 
            return recorderSetupError; 
    } 

    [audioRecorder prepareToRecord];  //***** LEAKING 512 BYTES 

    audioRecorder.delegate = self; 

    return recorderSetupError; 
} 

我不明白为什么在我发布audioRecorder时会发生泄漏 开始并设置为nil,我释放recordSettings并设置为nil? 请问有人可以开导我吗? 谢谢

1 个答案:

答案 0 :(得分:0)

尝试使用设备上的乐器运行您的应用。 AVFoundation有一些东西在模拟器上泄漏,但不在真实的硬件上!

但是,第二个想法,audioRecorder永远不会发布。也许尝试释放它 在方法结束时,或者可能使用自动释放?