Assume you have the following:
label.textProperty().bind(person.nameProperty());
Now assume the 'label' above is no longer part of the scene graph, and that it is no longer referenced from application code.
If 'person' is still around, 'label' is not being garbage-collected, due to a strong reference from the 'name' property of 'person' on the 'text' property of 'label', causing a memory leak.
This problem doesn't occur with bidirectional bindings, or low-level bindings, as in the below, given that those apparently use weak references:
label.textProperty().bindBidirectional(person.nameProperty());
label.textProperty().bind(new StringBinding() {
{
bind(person.nameProperty());
}
@Override
protected String computeValue() {
return person.nameProperty().get();
}
});
label.textProperty().bind(person.nameProperty());
Now assume the 'label' above is no longer part of the scene graph, and that it is no longer referenced from application code.
If 'person' is still around, 'label' is not being garbage-collected, due to a strong reference from the 'name' property of 'person' on the 'text' property of 'label', causing a memory leak.
This problem doesn't occur with bidirectional bindings, or low-level bindings, as in the below, given that those apparently use weak references:
label.textProperty().bindBidirectional(person.nameProperty());
label.textProperty().bind(new StringBinding() {
{
bind(person.nameProperty());
}
@Override
protected String computeValue() {
return person.nameProperty().get();
}
});