How to destroy a WebView from memory (iOS)

You must Login before you can answer or comment on any questions.


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
answer permalink
  • 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

  • Show 4 more comments

Whenever I ran across memory issues, the following post helped me clear most if not all of them up:

Your Answer

Think you can help? Login to answer this question!