Does UIWebView leak memory?

前端 未结 4 1055
陌清茗
陌清茗 2020-12-03 06:05

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?

相关标签:
4条回答
  • 2020-12-03 06:14

    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.

    0 讨论(0)
  • 2020-12-03 06:16

    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.

    0 讨论(0)
  • 2020-12-03 06:17

    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.

    0 讨论(0)
  • 2020-12-03 06:34

    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.

    0 讨论(0)
提交回复
热议问题