下载大文件时出现内存问题
我有一个大问题无法解决。 我正在制作一个 iPad 应用程序 &下载其中的 zip 文件(大文件,如 80Mb)&在某些时候,比如 75%,应用程序崩溃了...... 我执行了配置文件 &我可以看到内存如何随着下载而增长,所以,这显然是内存问题。 我的问题是,我该如何正确解决这个问题?我可以通过某种方式释放一些记忆吗? 告诉我是否需要在这里放置一些源代码&提前谢谢你! 问候!
I have a big issue that I can't solve.
I'm making an iPad app & downloading a zip file in it (large one, like 80Mb) & at some point, like 75%, the app is crashing...
I executed profile & i can see how the memory is growing with the downloading, so, it is clearly a memory issue.
My question is , how can I solve this properly? can I release some of this memory in some way.
Tell me if I need to put some source code here & thank u in advance!
Regards!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要将下载的字节保留在内存中,而是按照接收顺序将它们写入磁盘。如果您不知道如何操作,ASIHTTPRequest 可以帮助你。
Don't keep the downloaded bytes in memory but write them to disk in the order that you receive them in. If you don't know how, ASIHTTPRequest can help you.
您需要使用 NSOutputStream 并将其直接写入磁盘,而不是将其保留在内存中直到下载完成。这种方法将减少运行时内存的使用,并解决崩溃问题。
在API参考中查看这个方法
这里有一些关于Streams的参考:
https://developer. apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSOutputStream_Class/Reference/Reference.html
https://developer.apple。 com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSInputStream_Class/Reference/Reference.html
you need to use
NSOutputStream
and write it to the disk directly instead of keeping it in the memory till complete download. This approach will reduce the usage of runtime memory and will resolve your crashing issue.look at this method in the API reference
Here is some reference on Streams:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSOutputStream_Class/Reference/Reference.html
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSInputStream_Class/Reference/Reference.html