0

我有一个有窗口的应用程序。在那个窗口中有一个视图,并且该视图中有一个按钮。我想关闭窗口并释放窗口正在使用的内存。

那么,我们是否可以创建一个方法,该方法将遍历一个窗口并获取所有控件,以便我们可以使视图中的按钮等元素在使用后为空。

4

1 回答 1

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

于 2012-09-13T07:53:31.647 回答