Hello
I searched the forum for this problem but did not find any solution.
Accoring to "Apple's Instruments", the following code leads to a memory leak:
Code:
NSString *path = [[WinNavAppDelegate class] pathForDocumentWithName:@"file.plist"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
if (!fileExists) {
NSData *fileContents = [@"" dataUsingEncoding:NSUTF8StringEncoding];
[[NSFileManager defaultManager] createFileAtPath:path
contents:fileContents
attributes:nil];
}
NSMutableArray *bookDicts = [NSMutableArray arrayWithContentsOfFile:path];
if (bookDicts == nil)
{
path = nil;
path = [[NSBundle mainBundle] pathForResource:@"file"
ofType:@"plist"];
bookDicts = [NSMutableArray arrayWithContentsOfFile:path];
}
[_displayedObjects release];
_displayedObjects = [[NSMutableArray alloc]
initWithCapacity:[bookDicts count]];
for (NSDictionary *currDict in bookDicts)
{
Book *book = [[Book alloc] initWithDictionary:currDict];
[_displayedObjects addObject:book];
[book release];
}
The line which causes the problem is
Code:
NSMutableArray *bookDicts = [NSMutableArray arrayWithContentsOfFile:path];
What am I doing wrong?
Can anyone help me out of this?
Thank you
Regards
Phil