NSPropertyListSerialization 替代方案?
我可以使用任何代码来代替此代码片段吗?
NSString *anError = nil;
id plist;
plist = [NSPropertyListSerialization propertyListFromData:rawCourseArray mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&anError];
if (anError != nil){
[anError release];
}
上面的代码导致内存泄漏,我无法纠正。我尝试释放错误,但没有成功。是否有另一种方法可以将数组序列化为 plist 格式而不会泄漏?
问候, BX
所以我编辑了代码,现在看起来像这样,但仍然存在泄漏。一定是其他什么东西。我在...之后添加了循环
NSError *error = nil;
id plist;
plist = [NSPropertyListSerialization propertyListWithData:rawCourseArray options:/*unused*/0
format:NULL error:&error];
//NSArray *entries = (NSArray *)d;
NSArray *entries = (NSArray *)plist;
//for (eachCourse in rawCourseArray)
for (NSDictionary *entry in entries)
{
//LOOP
}
Is there any code that I can use in place of this code snippet?
NSString *anError = nil;
id plist;
plist = [NSPropertyListSerialization propertyListFromData:rawCourseArray mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&anError];
if (anError != nil){
[anError release];
}
The code above causes a memory leak which I can't correct. I try releasing the error but no luck. Is there another way to serialize an array into plist format without the leak?
Regards,
BX
So I edited the code and it now looks like this but still a leak. It must be something esle. I included the loop after...
NSError *error = nil;
id plist;
plist = [NSPropertyListSerialization propertyListWithData:rawCourseArray options:/*unused*/0
format:NULL error:&error];
//NSArray *entries = (NSArray *)d;
NSArray *entries = (NSArray *)plist;
//for (eachCourse in rawCourseArray)
for (NSDictionary *entry in entries)
{
//LOOP
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用的方法已过时,并且根据苹果文档即将被弃用,您应该使用
propertyListWithData:options:format:error:
而不是联动
The method you are using is obsolete and is about to be deprecated according to the apple docs, you should use
propertyListWithData:options:format:error:
insteadLinkage
该代码中没有内存泄漏。然而,存在潜在的崩溃。你不应该事实证明,-release
错误对象,因为你不拥有它。NSPropertyListSerialization
有一个糟糕的API。考虑使用+[NSPropertyListSerialization propertyListWithData:options:format:error:]
变体。你确定这里有内存泄漏吗?重现泄漏所需的最少代码量是多少?
There is no memory leak in that code. However, there is a potential crash. You should notIt turns out that-release
the error object, because you do not own it.NSPropertyListSerialization
has a terrible API. Consider using the+[NSPropertyListSerialization propertyListWithData:options:format:error:]
variant instead.Are you sure there's a memory leak here? What's the minimal amount of code you need to reproduce the leak?