我的方法是
-(void)readAppFile
{
NSString *plistPath = [self getDataFileDestinationPath];
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSMutableDictionary *temp = (NSMutableDictionary *) [NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];
if (!temp) {
NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
}
items = [[temp objectForKey:@"Items"] mutableCopy];
NSLog(@"temp %lu", (unsigned long)[temp retainCount]);
[temp release];
}
当我添加 [temp release];
时 - 但出了点问题,我的方法崩溃了。无法理解出了什么问题。正如我从内存泄漏工具中看到的那样 - 我需要释放此变量。有什么帮助吗?
最佳答案
[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];
方法返回自动释放的对象。
和自动释放池再次发送释放消息。
查看此链接,了解如何使用自动释放池 https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html
关于ios - 无法释放变量 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15880791/