[Solved] Uiwebview memory occupied too much, crash, memory overflow

UIWebView The memory occupation is too high, crash, memory overflow, if you need to refer to the following.

The project is running UIWebView on the simulator to read local magazines, no problem, but the real machine test often crashes with memory overflow.

After checking the data, the memory leak is caused by the js in Html, and the “WebKitCacheModelPreferenceKey” is set to 1 every time a connection is opened.

UIWebView add

– (void)webViewDidFinishLoad:(UIWebView *)webView {

[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@”WebKitCacheModelPreferenceKey”];

}

Solving the problem

Cause:

Your are going to have a big memory usage and leak a lot of data!

But there is a hack to solve this problem: revert what is 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 is to set it back to 0 everytime you open a link. You may easily do this by adding a UIWebViewDelegate to your UIWebView :

– (void)webViewDidFinishLoad:(UIWebView *)webView {

[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@”WebKitCacheModelPreferenceKey”];

}

So are you going to have much less crash due to “Low Memory” 🙂

The number of crashes is much reduced.

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

Similar Posts: