Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从Tianium中的内存中删除var对象_Javascript_Android_Ios_Garbage Collection_Titanium - Fatal编程技术网

Javascript 从Tianium中的内存中删除var对象

Javascript 从Tianium中的内存中删除var对象,javascript,android,ios,garbage-collection,titanium,Javascript,Android,Ios,Garbage Collection,Titanium,我有一个带有窗口的.js文件,然后我将所有布局添加到此窗口 first.js var Win = Ti.UI.CreateWindow({ backgroundColor : 'white' }); Win.open(); var View = Ti.UI.createView({ height : Ti.UI.SIZE, width : deviceWidth, backgroundColor : 'white' }); Ti.UI.CurrentWindo

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

first.js

var Win = Ti.UI.CreateWindow({
    backgroundColor : 'white'
});
Win.open();
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);
secun.js

var Win = Ti.UI.CreateWindow({
    backgroundColor : 'white'
});
Win.open();
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);
当我到期时,视图和标签占用的内存将被释放,或者是否需要执行其他操作来释放手机内存?就像将变量设置为null,这样关联对象就不再是Ti对象并且可以由垃圾收集器清理一样


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

如果不想访问任何视图或标签,请不要为其创建变量。例如,如果您没有访问任何其他地方的
标签
(仅在
视图
中添加),则建议您直接添加
标签

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'
    }
}));
更多信息,请查看
如果不想访问任何视图或标签,请不要为其创建变量。例如,如果您没有访问任何其他地方的
标签
(仅在
视图
中添加),则建议您直接添加
标签

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'
    }
}));
更多信息,请查看

如何释放我创建的变量的内存以及需要在函数的其他位置访问的变量?@Manuel_Rodrigues为此,在删除视图之前,您还可以使用视图的
removeAllChildren()
方法。我怎样才能释放我创建的变量的内存,这些变量需要在函数的其他位置访问?@Manuel_Rodrigues为此,在删除视图之前,您还可以使用视图的
removeAllChildren()
方法。