我正在使用此代码从config.plist文件中获取书名。然而,我的记忆管理是有问题的。 '[字典发布]'完全打破了应用程序,它退出。iOS发布不能按预期工作
代码在'[dict release]'被删除时起作用,但据我所知,它会导致内存泄漏。
bnames
是一个全球性的NSMutableArray
我在做什么错?
- (NSString *)loadBookname: (NSInteger) bookToLoad {
bookToLoad = [self bookOrder:bookToLoad];
//---get the path to the property list file---
plistFileNameConf = [[self documentsPath] stringByAppendingPathComponent:@"Config.plist"];
//---if the property list file can be found---
if ([[NSFileManager defaultManager] fileExistsAtPath:plistFileNameConf]) {
//---load the content of the property list file into a NSDictionary object---
dict = [[NSDictionary alloc] initWithContentsOfFile:plistFileNameConf];
bnames = [dict valueForKey:@"BookNames"];
[dict release];
}
else {
//---load the property list from the Resources folder---
NSString *pListPath = [[NSBundle mainBundle] pathForResource:@"Config" ofType:@"plist"];
dict = [[NSDictionary alloc] initWithContentsOfFile:pListPath];
bnames = [dict valueForKey:@"BookNames"];
[dict release];
}
plistFileNameConf = nil;
NSString *bookNameTemp;
bookNameTemp = [bnames objectAtIndex:bookToLoad - 1];
NSLog(@"bookName: %@", bookNameTemp);
return bookNameTemp;
}
'MRC'或'ARC'? – holex
如果他使用ARC,编译器会抱怨'释放'。 – Mundi