1

Dictionary の次の実装でメモリ リークが発生するのはなぜですか? 以下のスクリーンショットも参照してください。事実上、すべてのリークはこの方法によるものです。

- (void) setLocation:(NSString *) location:(NSString *) turnPage {
    NSLog(@"Start setLocation");
    //---get the path to the property list file---
    NSString *localPlistFileNameConf = [[self documentsPath] stringByAppendingPathComponent:@"Config.plist"];
    NSMutableDictionary *copyOfDict;
    //---if the property list file can be found---
    if ([[NSFileManager defaultManager] fileExistsAtPath:localPlistFileNameConf]) {
        //---load the content of the property list file into a NSDictionary object---
        NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:localPlistFileNameConf];
        //---make a mutable copy of the dictionary object---
        copyOfDict = [dict mutableCopy];
        [dict release];
    }
    else {
        //---load the property list from the Resources folder---
        NSString *pListPath = [[NSBundle mainBundle] pathForResource:@"Config" ofType:@"plist"];
        NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:pListPath];
        //---make a mutable copy of the dictionary object---
        copyOfDict = [dict mutableCopy];
        [dict release];
    }
    location = [self checkLocationValidity:location:turnPage];
    [copyOfDict setValue:location forKey:@"Location"];
    [self writeConfigToFile:copyOfDict];
    NSLog(@"End setLocation");
}

ここに画像の説明を入力

4

1 に答える 1

5

あなたはcopyOfDictどこにも解放していません。で始まるメソッドで作成されたオブジェクトを所有しているcopyため、それらのオブジェクトを解放する必要があります。NSDictionary効率上の理由から、クラス クラスタにちょっとした仕掛けがあるため、ソースを元の辞書として誤って報告している可能性があります。コードに対して Analyze を実行してみてください。これらのことが指摘されるはずです。

于 2012-08-30T14:26:53.167 に答える