ios - 无法释放变量 ios

标签 ios objective-c memory-management

我的方法是

-(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/

相关文章:

ios - 在构建时分配一个静态常量 ios xcode

r - R Windows 64 位版本中尚不支持长向量错误

c++ - 改进 malloc() 算法的下一步是什么?

ios - 我如何解决 iPhone 4 5 6 6+ 中的图像自动调整大小问题

ios - 用于改进代码完成的 Xcode 插件

ios - 访问由私有(private) managedObjectContext 创建的 CoreData 对象(在后台线程中创建)

ios - 如何在 iOS 上的 ImageView 下方添加阴影效果?

iOS:如何通过按 UIButton 更改 UIImageView

php - 将 HTTP POST JSON 参数发送到 PHP 页面 - iOS

java - 在 Amazon EC2 t2.micro 实例上运行的 Jar 内存不足