从钛内存中删除 var 对象

Remove var object from memory in titanium

我有一个带有 window 的 .js 文件,然后我将所有布局添加到此 window。

first.js

var Win = Ti.UI.CreateWindow({
    backgroundColor : 'white'
});
Win.open();

secun.js

var View = Ti.UI.createView({
    height : Ti.UI.SIZE,
    width : deviceWidth,
    backgroundColor : 'white'
});

Ti.UI.CurrentWindow.add(View);

var label = Ti.UI.createLabel({
    text : "Test",
    color : 'white',
    height : deviceHeight * 0.090,
    width : deviceWidth,
    backgroundColor : 'transparent',
    textAlign : 'center',
    font : {
        fontSize : deviceHeight * 0.0285,
        fontWeight : 'normal'
    }
});

View.add(label);

删除我制作的视图如下:

Ti.UI.CurrentWindow.remove(View);

当我到期时,View 和label 占用的内存被释放了,还是需要做其他事情来释放phone 内存?比如将变量设置为 null 以便不再关联 Ti 对象并且可以被垃圾收集器清理?

在我的项目中将变量设置为 null 的问题在于一些变量是在函数内部创建的,然后在该函数外部不可用。

如果您不想访问任何视图或标签,则不要为其创建变量。例如。如果您没有在其他任何地方访问 label(只是将其添加到 View),那么建议您直接将 label 添加为 :

View.add(Ti.UI.createLabel({
    text : "Test",
    color : 'white',
    height : deviceHeight * 0.090,
    width : deviceWidth,
    backgroundColor : 'transparent',
    textAlign : 'center',
    font : {
        fontSize : deviceHeight * 0.0285,
        fontWeight : 'normal'
    }
}));

更多请查看http://docs.appcelerator.com/platform/latest/#!/guide/Managing_Memory_and_Finding_Leaks http://www.tidev.io/2014/03/27/memory-management/