Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory Leak in NSMutableDictionary initWithContentsOfFile
    primarykey
    data
    text
    <p>This is my code: (customNames and customNamesArray are static variables)</p> <pre><code>-(void) loadCustomDataFromDisk { NSString *fullPath = [self filePathAndFileName: @"customData.plist"]; if ( ![[NSFileManager defaultManager] fileExistsAtPath: fullPath] ) { NSLog(@"Loading file fails: File not exist"); customNames = [[NSMutableDictionary alloc] init]; customNamesArray = [[NSMutableArray alloc] init]; } else { NSMutableDictionary *customItems = [[NSMutableDictionary alloc] initWithContentsOfFile: fullPath]; customNames = [customItems objectForKey: @"customNamesDict"]; customNamesArray = [customItems objectForKey: @"customNamesArray"]; if (!customItems) NSLog(@"Error loading file"); [customItems release]; } } -(void) saveCustomDataToDisk { NSString *path = [self filePathAndFileName: @"customData.plist"]; NSMutableDictionary *customItems = [[NSMutableDictionary alloc] init]; [customItems setObject: customNames forKey: @"customNamesDict"]; [customItems setObject: customNamesArray forKey: @"customNamesArray"]; BOOL success; success = [customItems writeToFile:path atomically:YES]; if (!success) NSLog(@"Error writing file: customDataDict.plist"); [customItems release]; } </code></pre> <p>According to Build and Analyze, I have a potential leak in loading customItems</p> <pre><code>NSMutableDictionary *customItems = [[NSMutableDictionary alloc] initWithContentsOfFile: fullPath]; </code></pre> <p>true enough, according to Instruments, I do have a leak in that part. But when I tried release or autoreleasing customItems, my app crashes. Even if I change NSMutableDictionary to NSDictionary, I still have the leak. How do I fix this? </p> <p>Any help would be very much appreciated. :) Thanks :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload