我有一个有窗口的应用程序。在该窗口中有一个视图,该视图中有一个按钮。我想关闭窗口并释放窗口正在使用的内存。
那么,我们可以创建一个方法来遍历一个窗口并获取所有控件,以便我们可以在视图中使用像按钮之类的元素在使用后为null。
答案 0 :(得分:1)
我假设您正在尝试释放内存并希望防止内存泄漏,您可以这样做
//create a window
var win = Titanium.UI.createWindow({
});
win.open();
//create a view
var view = Titanium.UI.createView({
});
win.add(view)//add view to window
//create button
var button = Titanium.UI.createButton({
});
view.add(button);//add button to view
//similarly add what ever you want according to your requirement
//this will free memory
win.remove(view); // view & button still exist
view = null; // deletes the view and its proxy, but not the button!
button = null;//deletes the button and delete all the elements what ever you have added
//if you have inserted views/tableviewrows/buttons and other elements into an array then nullifying it after their use like this
var SampleArray = [];
//added views,rows etc...to this SampleArray
SampleArray = null;
有关进一步参考,请点击此链接以管理内存和查找泄漏: https://wiki.appcelerator.org/display/guides/Managing+Memory+and+Finding+Leaks#ManagingMemoryandFindingLeaks-WhenTitaniumreleasesmemory