UIWebView占用大量内存 [英] UIWebView taking lots of memory

查看:148
本文介绍了UIWebView占用大量内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,当我使用任何网站URL加载 UIWebView 时,内存从30mb跳到140mb左右。
我正在使用ARC

In my app when i load UIWebView with any Website url the memory jumps from 30mb to around 140mb. I am using ARC



和解雇 UIWebViewController [ Viewcontroller 包含UIWebView] ,它不会释放内存。
任何人都可以帮我解决这个内存问题,还请在 ARC


and when dismissing the UIWebViewController[Viewcontroller which contains UIWebView], it doesnt releases the memory. Can any body help me how to solve this memory issues as well as please also provide me pointers of memory bestpractices in ARC

用于加载网页: -

For loading the webpage :-

NSURL *nsurl=[NSURL URLWithString:self.url];
    NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
    [webview loadRequest:nsrequest];

解雇Viewcontroller: -

FOr Dismissing the Viewcontroller:-

[self dismissViewControllerAnimated:YES completion:^{
    webview.delegate=nil;
    webview=nil;
}];

提前致谢:)

推荐答案

哇,今天我们也遇到了这个问题。当我们尝试加载包含大量图片或巨大网页的网页时,很容易崩溃。我们还发现内存使用了近200M。

wow, today we also meet this problem. when we try to load a web page which contain lots pictures or a huge web page, it's easy to crash. we also find the memory used nearly 200M.

最后我们发现我们可以删除网页视图的内存缓存

finally we find that we could remove the memory cache of web view

[[NSURLCache sharedURLCache] removeAllCachedResponses];

您可以在收到内存警告时尝试。或者你可以在dealloc方法中调用它。

you can try it when you receive memory warning. or you can call it in the dealloc method.

如果它仍有一些问题,请尝试通过调用来限制内存缓存大小

if it still have some problems, try to limit the memory cache size by call

[[NSURLCache sharedURLCache] setMemoryCapacity:size]



祝你好运!

good luck!

这篇关于UIWebView占用大量内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆