2010-04-01 76 views
1

對不起,格式化代碼難以在此顯示正確?內存泄漏問題

我想了解從我的應用程序運行儀器 得到的讀數,這些讀數告訴我我正在泄漏內存。 有許多,頗有其實不在少數,這也會從裏面 報道的基礎上,AVFoundation CoreGraphics在等,我認爲我在沒有 控制,因此應該忽略,如:

malloc的32個字節:96個字節,AVFoundation,prepareToRecordQueue

或 malloc的128個字節:128個字節,CoreGraphics中,open_handle_to_dylib_path

我是在假設這些東西該系統將解決糾正?

但隨後但是也有一些報道,我相信我 負責,如泄漏:

這針對此線電話報告泄漏2.31KB

[自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啓動,並設置爲無,我釋放recordSettings並設置爲零? 任何人都可以啓發我嗎? 謝謝

回答

0

嘗試使用設備上的儀器運行您的應用程序。 AVFoundation有一些在模擬器上泄漏的東西,但不要在真正的硬件上!

但是,第二個想法是,audioRecorder從未發佈。也許嘗試在方法結束時釋放它 ,或者使用autorelease?