英文:
Release NSData not release all memory
问题
我正在使用这段代码获取特定文件的NSData
:
NSData* data = [[NSData alloc] initWithContentsOfURL:object.fileURL];
在这行代码之前,内存使用量为18MB,之后变成了66.1MB。在这之后,我想释放这个对象(非ARC类),所以我调用了[data release];
。然后数据的内存使用量从18MB变成了43MB。
有什么想法是什么问题?我该如何修复它?
英文:
I'm using this code to get NSData
of a specific file:
NSData* data = [[NSData alloc] initWithContentsOfURL:object.fileURL];
Before this line the memory usage was 18MB and after this line it become 66.1.
right after i want release this object(Non-ARC class) so i call [data release];
And the data memory usage becomes 43 instead of 18MB.
Any idea what can be the problem? how i. can fix it?
答案1
得分: 2
这很可能不是一个实际的问题。应用程序并不总是返回所有的内存,因为它们可能会再次需要它。操作系统可能会稍后需要回收内存,但与此同时,如果没有压力的话,让应用程序保留已分配的内存会更高效。
如果你继续分配和释放内存,应用程序的内存占用会继续增长,还是会稳定在43MB?如果它继续增长,那么你确实有一个内存泄漏问题,并且可以使用各种工具来调试它。如果它只有一次性的跳跃,那就是故意的。
英文:
This is likely not an actual problem. Apps do not always return all memory since they may need it again. The OS may later require the memory back, but in the meantime it is much more efficient to let apps keep allocated memory if there is no pressure.
If you continue to allocate and release memory, does the app's memory footprint continue to grow, or does it stabilize at 43MB? If it continues to grow, then you do have a memory leak, and can debug that using various tools. If it has a one-time jump, then that is intentional.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论