在我的应用程序中,当我使用任何网站 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 占用大量内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!