Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-13382

Cordova iOS - Method to correctly destroy CDVViewControllers webView object


    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: cordova-ios 4.5.0
    • Fix Version/s: None
    • Component/s: cordova-ios
    • Labels:


      We have an app where we are using multi CDVViewController instances where a user can switch between hybrid apps within the native app.

      The issue that as been lingering for a couple of years is that even though a CDVViewController instance can be set to nil, the webview contained within still remains in memory. This can be observed when using the safari debugger.

      This is particularly troublesome when the webview is 'closed', then the content files in the webview are updated, and finally the webview is recreated, showing the old content. Performing a cmd-r in safari debugger refreshes the view and shows the updated content.

      We can also do this a [UIWebView reload], but it is not possible if the app changes it's URL to a none physical path, e.g. file:///xxxxx/myApp/www/index.html becomes file:///xxxxx/myApp/www/home, then we get a page load error.

      I've been able to get the webview completely removed by doing the following:

      add the following method to CDVViewController:

      -(void)destroyWebView {
          self.webViewEngine = nil;

      then in my view controllers destroy method:

          [self.webViewEngine loadHTMLString:@"about:blank" baseURL:nil];
          [self.pluginObjects removeAllObjects];
          [self.webView removeFromSuperview];
          [self destroyWebView];

      Setting webViewEngine to nil is an unavoidable step to completely destroying the webview, but it is readonly.
      Therefore, i would really appreciate this destroyWebView method, or a similar cleanup method being added.

      Android has a method to clean up which is CordovaWebViewImpl.handleDestroy().
      This destroys all the plugins, sets the URL to 'about:blank' and then executes engine.destroy()

      Many thanks!




            • Assignee:
              nickdeakin Nick Deakin
            • Votes:
              0 Vote for this issue
              5 Start watching this issue


              • Created: