Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Best practice with Listeners to avoid memory leaks

drenda81Apr 14 2013 — edited Apr 15 2013
Hi guys,
I'm using Javafx to develop an application. I'm creating views with fxml. I'm experiencing some memory problems perhaps because I can not understand the life cycle of the controller and the views.

For example, the listeners that I add in the controller to the components of ui, must be removed before going out from the view?

And in a case in which there is a inner listener? For example:
tabellaClienti.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Cliente>() {
			@Override
			public void changed(ObservableValue<? extends Cliente> property, Cliente oldSelection, Cliente newSelection) {
				seleziona(newSelection);
			}
		});
in this case the listener when is destroyed?
I'm experiencing that I got the same view (with all components) in memory many times.

There is a guideline to follow to be sure to avoid making mistakes?

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 13 2013
Added on Apr 14 2013
2 comments
751 views