Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView taking lots of memory

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

here is the image for the same
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];

FOr Dismissing the Viewcontroller:-

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

Thanks in Advance :)

like image 321
DAMM108 Avatar asked Mar 31 '14 18:03

DAMM108


1 Answers

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];

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!

like image 152
TinyMonk Avatar answered Nov 15 '22 19:11

TinyMonk