首页 > Web开发 > 详细

UIWebView内存占用过高、崩溃、内存溢出

时间:2015-03-17 08:11:48      阅读:583      评论:0      收藏:0      [点我收藏+]
UIWebView内存占用过高、崩溃、内存溢出,有需要的朋友可以参考下。

项目当中模拟器上运行UIWebView读取本地杂志,没问题,真机测试经常内存溢出崩溃。
查了资料因为Html里的js 导致的内存泄漏,每次打开一个连接就会把“WebKitCacheModelPreferenceKey”设置成1。
UIWebView 增加
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
}
解决问题
原因:
Your are going to have a big memory usage and leak a lot of data!

But there is a hack to solve this problem: revert what is done when you open a link.
In fact, the key property which leads to this leak is the WebKitCacheModelPreferenceKey application setting. And when you open a link in a UIWebView, this property is automatically set to the value "1". So, the solution is to set it back to 0 everytime you open a link. You may easily do this by adding a UIWebViewDelegate to your UIWebView :
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
}

So are you going to have much less crash due to "Low Memory" :)

崩溃次数减少很多。

国外小哥原文地址:http://blog.techno-barje.fr//post/2010/10/04/UIWebView-secrets-part1-memory-leaks-on-xmlhttprequest/

UIWebView内存占用过高、崩溃、内存溢出

原文:http://my.oschina.net/are1OfBlog/blog/387695

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!