Search code examples
javascriptandroidgarbage-collectiontitanium

memory management in Titanium android


I'm not sure of what this does.

For example:

var myView = Ti.UI.createView({
    height : "10.8%",
    top : 0,
    width : "30%",
    right : 0,
    zIndex : 100
});



var myLabel =Ti.UI.createLabel({
    text : (local).toString().toUpperCase(),
    color : "#444444",
    height : Ti.UI.SIZE,
    width : Ti.UI.SIZE,
    font : {
        fontSize : deviceWidth * 0.03,
        fontFamily : "Dosis-SemiBold"
    },
    backgroundColor : "transparent",
});

myView.add(myLabel);

In this case I have added a Label to my View.

If I remove the Label from the View with: myView.removeAllChildren();, the Label guest removed from the view, but will the label removed from memory by the GC or due I really need to set the Label to null?


Solution

  • You will still have your label in memory, in fact you can add it back to the view to actually see that it s still around.

    you have to null that variable to completely remove it from memory.

    let me quote the docs

    Problems arise when you leave references to objects that you no longer need. You can remove references by setting variables and objects to null when you no longer need them. This includes both variables and objects you create to represent your app's business logic, but also objects that represent Titanium components such as Views or Images.

    have a good read :)