问题描述
在我的应用程序中,当我使用任何网站 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
当关闭包含 UIWebView 的 UIWebViewController[Viewcontroller] 时,它不会释放内存.任何人都可以帮助我如何解决这个内存问题,还请在 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
用于加载网页:-
NSURL *nsurl=[NSURL URLWithString:self.url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webview loadRequest:nsrequest];
对于关闭视图控制器:-
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]
祝你好运!
这篇关于UIWebView 占用大量内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)