Roland
Roland

Reputation: 18415

Bindings and memory leaks

Problem

Example use case:

Question

Could this cause a memory leak and do you have to perform a manual unbind in the old topology view before you create the new one? Similar to the bindings, do you have to remove event handlers manually?

The bindings and the event handlers are inside the control. So once the control isn't accessible anymore it should be possible that it's garbage collected. So I think you don't have to do anything, but I don't know.

Thank you very much for the expertise!

Upvotes: 1

Views: 385

Answers (1)

eckig
eckig

Reputation: 11154

If you look into the 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.

So if you use or extend the default Bindings the Garbage Collector should be able to do its work.

If you do not, be sure do implement and call Binding.dispose().

As always: If an object is no longer referenced by any other object it gets garbage collected (at some point in the future). So usually one does not need to specifically implement in this direction, as it tends to clutter the code.

Upvotes: 1

Related Questions