我有两个绑定(bind)StringProperty
对象。我想要 Binding
是弱的,因此一旦绑定(bind)对象之一被 GC,它就有资格进行垃圾收集。
看这个例子:
StringProperty obj1 = new StringProperty("Object1");
StringProperty obj2 = new StringProperty("Object2");
obj2.bind(obj1);
obj2 = null;
如何创建弱引用,以便
Bindung
在第 3 行创建的可以收集吗?
最佳答案
虽然是一个迟到的回答者,但我在 Property.bind(...)
JavaDoc 中找到了这个片段。 :
Note that JavaFX has all the bind calls implemented through weak listeners. This means the bound property can be garbage collected and stopped from being updated.
因此,您的绑定(bind)应该默认保持弱引用。
关于binding - 我可以在 JavaFX 中创建弱绑定(bind)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23649443/