UIWebView memory usage, crashes, memory overflow

Source: Internet
Author: User

UIWebView memory consumption is too high, crashes, memory overflow, the need for friends can refer to.

In the project where the emulator runs UIWebView read Local magazine, no problem, the real machine test often crashes with memory overflow.
I checked the data. Because of the memory leak caused by JS in HTML, the "Webkitcachemodelpreferencekey" is set to 1 each time a connection is opened.
UIWebView Increase
-(void) Webviewdidfinishload: (UIWebView *) WebView {
[[Nsuserdefaults Standarduserdefaults] setinteger:0 forkey:@ "Webkitcachemodelpreferencekey"];
}
Solve the problem
Reason:
Your is going to has a big memory usage and leak a lot of data!

But there was a hack to solve this problem:revert what was done when you open a link.
In fact, the key property which leads to this leak is the Webkitcachemodelpreferencekey application setting. And when you open a link in a UIWebView, this property is automatically set to the value "1". So, the solution are to set it back to 0 everytime you open a link. Easily do the adding a uiwebviewdelegate to your UIWebView:
-(void) Webviewdidfinishload: (UIWebView *) WebView {
[[Nsuserdefaults Standarduserdefaults] setinteger:0 forkey:@ "Webkitcachemodelpreferencekey"];
}

So is going to has much less crash due to "low Memory":)

The number of crashes is much reduced.

Foreign small Brother original address: http://blog.techno-barje.fr//post/2010/10/04/UIWebView-secrets-part1-memory-leaks-on-xmlhttprequest/

UIWebView memory usage, crashes, memory overflow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.