You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2019/02/12 17:24:22 UTC

[GitHub] mgatto opened a new issue #522: Excessive Memory Leaks with AJAX loading of HTML

mgatto opened a new issue #522: Excessive Memory Leaks with AJAX loading of HTML
URL: https://github.com/apache/cordova-ios/issues/522
 
 
   # Bug Report
   
   ## Problem
   
   An app heavily uses AJAX to load HTML files from the local bundle. This causes UIWebView to leak too much memory. 
   
   ### What is expected to happen?
   
   Memory usage for an IOS Cordova app loading HTML should remain relatively stable after initial loads. Reloads of the HTML should not lose memory to leaks with each load.
   
   ### What does actually happen?
   
   Each usage of jQuery's `load()` method or manual usage of `$.ajax()` to load HTML files increased total memory by over 1MB on each call. The cumulative effect of these leaks eventually causes the app to use more memory without limit, until the app crashes, in my case at a little over 1GB of consumed memory just for this app.
   
   ## Information
   
   Extensive research claimed that switching from UIWebView to WkWebView would resolve leaks coming from "normal" JS usage. This was not possible for our app at this time. 
   
   I upgraded the app to the very latest versions of jQuery, jQuery UI, jQuery Mobile and MustacheJS, to little effect on memory usage.
   
   Incredibly, this post from 2010 "fixed" the issue, which is still extant in UIWebView: http://blog.techno-barje.fr/post/2010/10/04/UIWebView-secrets-part1-memory-leaks-on-xmlhttprequest/ 
   
   The recommended code is:
   
   ```
   [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey" ];
   ```
   Adding the recommended code to the method `- (void)webViewDidFinishLoad:(UIWebView*)webView` in `CDVUIWebViewDelegate.m` fixed the issue. Memory usage then remained steady at about 120MB over numerous, manual testing loads according to XCode's memory tracking on a DEBUG build of our Cordova app, instead of ballooning to 1GB+ after only a few test loads.
   
   Adding the recommended code to the the same function in `CDVUIWebViewNavigationDelegate.m` had no effect.
   
   ### Environment, Platform, Device
   
   iOS 10, 11 and 12. Multiple iPads with 1GB to 3GB RAM.
   
   ### Version information
   
   * cordova-ios 4.5.5
   * cordova 8.1.2
   
   ## Checklist
   
   - [ x] I searched for existing GitHub issues
   - [ x] I updated all Cordova tooling to most recent version
   - [ x] I included all the necessary information above
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org