binding - 我可以在 JavaFX 中创建弱绑定(bind)吗?

标签 binding javafx weak-references

我有两个绑定(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/

相关文章:

javascript - 如何将 std::function 绑定(bind)到 JavaScript V8?

java - 将 VBox 和 StackPane 放入另一个 StackPane 后按钮不起作用

swift - 弱引用和无主引用有什么区别?

java - 弱引用可维护性

ios - 积木中的弱势 self

objective-c - 如何使用 NSArrayController 对 NSTableView 中的行重新排序

C# wpf,从文本框绑定(bind)到 dataGridColumn

c# - Xamarin Forms BindableProperty 在构造函数之前更改

使用 JavaFX 播放 jar 中的声音时出现 java.lang.NoClassDefFoundError

multithreading - 使用 javafx.concurrent 的 JavaFX 网络后台任务