简体   繁体   中英

Does UIWebView leak memory?

If your iPhone app uses a UIWebView, and loads many pages with large images, you may find that you are leaking memory. Can this be resolved?

Try adding

[webView loadHTMLString: @"" baseURL: nil];

right before you release the webview. For a leak in 4.2.1 relating to displaying a PDF in a UIWebView this solves most of the leak problems for me.

It is a known problem.

Marco Arment mentions the leak here. http://blog.instapaper.com/post/60628543

There isn't a lot you can do. One option in to "intercept" the html try to truncate parts that you don't need. Obviously, this won't likely work for a general purpose webview.

In the meantime, you may just have to wait for an update from Apple.

I got a

received memory warning, level 1

and then the application crashed with the huge text size in the web view.

This article helped me, solving the leak issue. Very easy and straightforward to use.

I did this and it seems to help (looking at Leaks and running through simulator anyway):

MyWebViewController *myWebViewController = [[[MyWebViewController alloc] initWithNibName:@"MyWebView" bundle:[NSBundle mainBundle]] autorelease];

It was the "autorelease" that seems to help in that the leak is not getting bigger on each webview I open.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM