In my app when i load UIWebView
with any Website url the memory jumps from 30mb to around 140mb.
I am using 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];
FOr Dismissing the Viewcontroller:-
[self dismissViewControllerAnimated:YES completion:^{
webview.delegate=nil;
webview=nil;
}];
Thanks in Advance :)
add
before this line
nil ing your webView should be taken care of by ARC. Don't refer to the web view in the completion block.
Just some things you should check:
strong
reference to itsview
, and this view retains all the subviews as long as you keep them inside the view hierarchy, so any additional properties should beweak
, including yourwebView
property.nil
" everything. ARC willnil
all itsstrong
references atdealloc
automatically.weak
references neither. Moreover on iOS 5+weak
references becomenil
automatically if the referenced object gets deallocated somewhere else.I think that most likely your whole view controller is getting retained somewhere, and thus its
view
and thewebView
.Make sure the you only keep
weak
references to the controller and let it be retained by a container or presenting controller so it gets released automatically as long as it gets popped or dismissed.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
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
good luck!
UIWebViewController
live in memory. (Cmd + I in Xcode, let Instruments open, select Allocations, and type UIWebViewController in the search bar)UIWebViewController
object at more than one place.I think you forgot to remove the UIWebView from the view hierarchy. This would cause an extra retain count and prevent the memory from being reclaimed when you nil'd out the property.
There is no sense to search for a problem until you are sure that problem exists.
There are two possibilities why memory usage is so high:
1.UIWebView is not deallocated.
2.It is some system caching or some specific iOS memory processing algorithm.
In second case you can do nothing. To check first case you can try to use instruments or just subclass UIWebView and add logging to dealloc method.
Do not forget to change UIWebView to MyUIWebView in your code.
And only if you will be sure that UIWebView is not deallocated you should start to search for strong pointers, retain circles and so on.