I currently have a UIWebView that is displayed within a modal view. It is basically a detail view that provides a view of a page when the user clicks a link. When the view is dismissed and then brought up again (when the user clicks another link), the previously-loaded content is still visible and the new content loads "on top" of the last content. This makes sense because the instance of the UIWebView persists between sessions and is only released when the memory is needed.
However, I would like to completely clear the UIWebView when the modal view is dismissed so that 1) content is cleared and 2) memory is freed. Thus far my research and attempts have not found an answer. These links haven't worked for me:
I've tried [[NSURLCache sharedURLCache] removeAllCachedResponses];
and setting the webView to nil and manually releasing the webView upon modal-view-dismiss to no avail. Any thoughts from the wizened masses?
Sometimes loadHTMLString
is too slow. You also can use:
[webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML = \"\";"];
I'm not sure if that will free up much memory though...
Releasing the web view is probably the best approach. If a view is in a view hierarchy (has a superview) you must call removeFromSuperview to get the superview to release the view.
You could also load an html string for an empty document:
[webView loadHTMLString:@"<html><head></head><body></body></html>" baseURL:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With