Nasty NSPropertyListSerialization Leak

十年热恋 提交于 2019-12-12 23:03:58

问题


NSString *anError = nil;
 id plist;
 plist = [NSPropertyListSerialization propertyListFromData:rawCourseArray mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&anError];
 if (anError != nil){

  [anError release];
 }

The above code causes a memory leak every time I call it. I am releasing the error but still there is a leak. I haven't seen any resolution to this issue. I posted this already and most respond that this is not a leak. But see here in the leak performance tool:

I need this fixed because eventually my app crashes. Any ideas? Many thanks


回答1:


I had the same problem. Used propertyListWithData:options:format:error: with same result. Used NSDictionary initWithContentsOfFile with same result:

Leaked Object # Address Size Responsible Library Responsible Frame NSCFNumber,19 < multiple > 304 Bytes MediaToolbox FigRemote_CreatePropertyListFromBinaryPListData

FWIW - I only have dictionaries and arrays and strings in the pList, no numbers.

The issue is not the error object (or string in your method). The issue is not plist above, since it should be autorelease. In the end, I gave up and reimplemented using JSON and:

http://stig.github.com/json-framework/api/index.html

==> no more leak.

Best, Fred




回答2:


I've had the same problem before.

Basically this is because your error variable got released without initiating it. So what you can do is try to init your NSString *error to an empty string before releasing it. Or not releasing it at all.



来源:https://stackoverflow.com/questions/4675730/nasty-nspropertylistserialization-leak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!