How to destroy a WebView from memory (iOS)


I'm trying to remove a webView from memory, removing from its parent component and assigning null value to it.

This works with any other component in the same view, but not for the webView. I've tested with xCode profile tools. Using Allocations tools, I see how the rest of components go to transitory when I manually unload them. But the webview remains "Living". If I load the view again, a new webView is created, with an important memory leak.

Am I doing something wrong? How can I achieve this?

this is the module where I create the parent View, I've added a public 'unload' method for testing purpposes

module.exports = function (args) {

    var args = args || {};

    var view = Ti.UI.createView(Styles.FullVIew);

    var titleView = new TitleModule('Section title');

    var webView = Ti.UI.createWebView({
        right:45, left:460, bottom:0,

    var images = [

    var gallery = new GalleryModule({
        top:titleView.height, left:20, width:400, bottom:10,


    //optional public function to unload components when module is hide and liberate memory
    view.unload = function(){

        viewTitle = null;
        webView = null;  //does nothing???
        gallery = null;
        //view = null;  //tried this, but is the same

    return view;

testing on iOS 5, xCode 4.2.1, MacOS 10.7.3

2 Answers

  • Try to set the html property to null before nullifying the webview. maybe this will free the content of the webview.

    — answered 4 years ago by Dan Tamas
    • nop :( assigning null to html throws an exception. I tried an empty string instead, but the webView component is still alive. Does not jump to the "transitory" column.

      — commented 4 years ago by Javier Rayon
    • buggy bug maybe? :)

      — commented 4 years ago by Dan Tamas
    • Maybe, but is hard to confirm. I'll try the MemoryPool technique and I'll see what conclusion I have.

      — commented 4 years ago by Javier Rayon
    • Ok, after a few tests these are my conclussions:

      • the bug only occurs loading local files. With remote URLs the webview is correctly released on close. The local file is quite simple (plain html), so I think the issue is not related with the file's content.

      • setting html or url properties to any value such as null or empty string before destroy the component does not change anything.

      • I tried remove the webView from the parent view, set the webView to null and close the window, and the component is still there. If I create a new instance of the view, a new webView is allocated in memory.

      • My workaround will be read the content of the html file manually set to the html property (fortunately are very simple files), but I do not consider a final sollution.

      I'll open a JIRA ticket when I create a test case.

      — commented 4 years ago by Javier Rayon
    • Hi Javier,

      Did you get any further on this topic? I am running into a like wise issue:

      Kind regards

      — commented 4 years ago by Wienke Giezeman
    • Any progress with this issue? Having the same problem in SDK 3.0.0


      — commented 3 years ago by Javier Prieto
    • Same issue with SDK 3.0.2 GA. Sad, very sad…

      — commented 3 years ago by Pascal Achard
  • Whenever I ran across memory issues, the following post helped me clear most if not all of them up: