Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSMutableDictionary initWithContentsOfFile中存在内存泄漏_Ios_Memory Management_Memory Leaks_Nsmutabledictionary - Fatal编程技术网

Ios NSMutableDictionary initWithContentsOfFile中存在内存泄漏

Ios NSMutableDictionary initWithContentsOfFile中存在内存泄漏,ios,memory-management,memory-leaks,nsmutabledictionary,Ios,Memory Management,Memory Leaks,Nsmutabledictionary,这是我的代码:(customNames和customNamesArray是静态变量) 根据构建和分析,我在加载自定义项时有一个潜在的漏洞 NSMutableDictionary *customItems = [[NSMutableDictionary alloc] initWithContentsOfFile: fullPath]; 没错,根据仪器,我确实在那部分有漏洞。但当我尝试发布或自动删除customItems时,我的应用程序崩溃了。即使我将NSMutableDictionary更改为N

这是我的代码:(customNames和customNamesArray是静态变量)

根据构建和分析,我在加载自定义项时有一个潜在的漏洞

NSMutableDictionary *customItems = [[NSMutableDictionary alloc] initWithContentsOfFile: fullPath];
没错,根据仪器,我确实在那部分有漏洞。但当我尝试发布或自动删除customItems时,我的应用程序崩溃了。即使我将NSMutableDictionary更改为NSDictionary,我仍然存在漏洞。 我该如何解决这个问题


任何帮助都将不胜感激。:)谢谢:)

我看你的代码是正确的。你们可以在这里看到答案,也许会有帮助-


我只有一个问题:你创建了NSString*fullPath,却从不释放它。是自动释放字符串吗?如果是这样-您的代码很好。

您必须保留customNames和customNamesArray,因为您使用的是来自字典customItems的引用,在传递引用后,您将释放它

customNames=[[customItems objectForKey:@“customNamesDict”]保留]

customNamesArray=[[customItems objectForKey:@“customNamesArray”]保留]


现在您可以发布customItems了。

很难看出代码中有什么错误。你能告诉我你是怎么发布的吗?你显然需要发布它,但很难知道为什么它会崩溃而没有看到更多的代码。嗨,我编辑了原来的帖子来添加更多的代码:)谢谢你的回复。
NSMutableDictionary *customItems = [[NSMutableDictionary alloc] initWithContentsOfFile: fullPath];