我有一个带有选项卡的TabPane
。我正在创建新的Tab
,将其添加到我的TabPane
中。
然后,我通过编程方式关闭选项卡并从TabPane
中删除它。
Tab
未设置为null
。这是正确的行为吗?如何清除/销毁此Tab
对象?
我有一个带有选项卡的TabPane
。我正在创建新的Tab
,将其添加到我的TabPane
中。
然后,我通过编程方式关闭选项卡并从TabPane
中删除它。
Tab
未设置为null
。这是正确的行为吗?如何清除/销毁此Tab
对象?
myTab = null;
之后让垃圾回收器完成它的工作。如果您还有对该对象实例的其他引用,请对它们执行相同的操作。
你的选项卡可能仍然有一个持有引用的事件处理程序。
tab.setOnClosed(null);
例子:
// I make setOnClose handler in my constructor
// My set on close handler will close my project
tab.setOnClosed(new EventHandler<Event>() {
@Override
public void handle(Event t) {
closeProject();
}
});
// Somehow my setOnClose handler still exists after closing the tab
public void closeProject() {
// Setting the setOnClose handler to null fixes the garbage collection issue for me
tab.setOnClosed(null);
tab.setUserData(null);
tab = null;
}