Can I create weak bindings in JavaFX?

I have two related objects StringProperty. I want it to Bindingbe weak, make it suitable for garbage collection, as soon as one of the related objects is GCed.

Check out this example:

StringProperty obj1 = new StringProperty("Object1");
StringProperty obj2 = new StringProperty("Object2"); 
obj2.bind(obj1);
obj2 = null;

How to create a weak link so that you can build Bindungcreated in line 3?

+4
source share
3 answers

Despite the late anderser, I found this snippet in the Property.bind(...)JavaDoc :

Note that JavaFX has all the binding calls implemented through weak listeners. This means that the associated property can be collected and stopped from garbage.

.

+7

property1.bindBidirectional(property2) obj2.bindBidirectional(obj1), com.sun.javafx.binding.BidirectionalBinding, WeakReference.

, , , . , , .

0

? , .

-1

Source: https://habr.com/ru/post/1540484/


All Articles