I have TabPanewith Tabin it. I create a new Tabone by adding it to mine TabPane. Then I close the tab and programmatically delete it from TabPane.
TabPane
Tab
Tabnot set to null. Is this the right behavior? How to clean / destroy this object Tab?
null
The garbage collector does not destroy objects on which you still keep the link.
Assuming you have a local variable or field myTab, just assign
myTab
myTab = null;
. , .
EventHandler, .
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; }