Massive UIWebView Memory Leak
Successive calls to
[self.webView loadHTMLString:[_detailItem htmlText] baseURL:nil];
were causing my memory usage to explode on iPad iOS 4.3 (device). Simply commenting out that line fixed the problem, but I need to be able to display HTML content.
The official docs don't mention anything about UIWebView
retaining/releasing content or caching, nothing at all about its memory management details.
Now, the instance itself is instantiated in a NIB file and all I do is call the method above with new content. Would I have to release/alloc-init UIWebView
at each request to avoid this issue? Is this a known problem?
I know the p开发者_如何学JAVAroblem is not with my code because simply commenting out that line fixes the issue. My objects are deallocated normally. UIWebView
is to blame.
UPDATE
Releasing and reallocating the web view every time did indeed fix the problem. So, heads up for anyone using web view to make consecutive loads: allocate, execute load, release, allocate, ... and you won't have any memory problems.
Not enough points to comment.
A related post StackOverflow Reused UiWebView quotes an Apple Engineer "Don't reuse UIWebViews, that's not how they were meant to be used."
If you really need to reuse the UIWebView, you can use Java Script. Something along the lines: [self.definitionWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"setBody(\"%@\");", _detailItem htmlText]];
精彩评论