解压时内存泄漏
对于我的内存泄漏问题,我希望得到一些支持。
我的数组中有数据,已使用 NSKeyedArchiver 存档。我后来取消存档。从功能的角度来看,它运行良好,但是当我运行内存泄漏工具时,我在取消归档时遇到内存泄漏。
这是代码:
NSArray *arrayToLoad = [[NSArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithFile:path]];
ballPath = [arrayToLoad copy];
[arrayToLoad release];
其中 ballPath 是一个 NSArray。
Instruments 表明 100% 的泄漏与上面代码中的第一行有关。我显然错过了一些东西,但无法找出什么。我认为 [NSKeyedUnarchiver unarchiveObjectWithFile:path] 是自动释放的,并且 arrayToLoad 已释放,所以我迷路了。
任何建议表示赞赏。
I would appreciate some support regarding a memory leak I have.
I have data in an array that I have archived with NSKeyedArchiver. I later on un-archive it. From a functional point of view it is working well, but when I run Instruments for Memory Leaks I get memory leaks when un-archiving.
This is the code:
NSArray *arrayToLoad = [[NSArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithFile:path]];
ballPath = [arrayToLoad copy];
[arrayToLoad release];
Where ballPath is an NSArray.
Instruments indicates that 100% of the leak is related to the first line in the code above. I am clearly missing something but am not able to find out what. I think that [NSKeyedUnarchiver unarchiveObjectWithFile:path] is autoreleased and the arrayToLoad is released, so I'm lost.
Any advice is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢你们。我仅在使用 arrayToLoad 的副本设置 ballPath 后才读取 ballPath 中的值。仍然没有弄清楚为什么我有内存泄漏,但下面的代码可以工作,即使我不以任何方式感到自豪:
Thanks guys. I am only reading values in ballPath after it is set with the copy of arrayToLoad. Still have not figured out why I have a memory leak, but the below code works, even if I'm not in any way proud of it: