绑定和内存泄漏

Bindings and memory leaks

问题

示例用例:

问题

这会不会导致内存泄漏,您是否必须在创建新拓扑视图之前在旧拓扑视图中执行手动解除绑定?与绑定类似,是否必须手动删除事件处理程序?

绑定和事件处理程序在控件内。因此,一旦控件不再可访问,它就可能被垃圾回收。所以我认为你不需要做任何事情,但我不知道。

非常感谢您的专业知识!

如果您查看 JavaDocs

[...] All bindings in our implementation use instances of WeakInvalidationListener, which means usually a binding does not need to be disposed. But if you plan to use your application in environments that do not support WeakReferences you have to dispose unused Bindings to avoid memory leaks.

因此,如果您使用或扩展默认值 Binding,垃圾收集器应该能够完成它的工作。

如果不这样做,请务必执行并调用 Binding.dispose()

一如既往:如果一个对象不再被任何其他对象引用,它就会被垃圾收集(在将来的某个时候)。所以通常不需要在这个方向上专门实现,因为它往往会使代码混乱。