What's the least horrible way to remove all listen...
# tornadofx
a
What's the least horrible way to remove all listeners on a property? without having to keep reference to each and every one of them.
m
The easiest way is to just dispose of the object 😛
💯 1
otherwise, you either have to keep a list of all the listeners, use bindings instead, or use a different strategy
a
Unfortunately, I need a property not a binding, I guess I could just dispose the object 😐 Tried all weird things with weak references but didn't think of that for some reason 😅
m
of course you can bind the property to other properties or a function/lambda but that may not work depending on what you are doing
a
Yup, it's a bit complicated, I was trying to bind two properties of different types bidirectionally, one of which will be bound bidirectionally to other properties of other types very frequently. To achieve it I tried adding listeners to both properties and propagating the values between them, but it was creating memory leaks even when I used `WeakChangeListener`s.
m
you can use "bindBidirectional" and then unbind
Copy code
val test = booleanProperty(false)
val other = booleanProperty(false)
test.bindBidirectional(other)
you just have to call unbind() on both or
test.unbindBidirectional(other)
a
Yup, but I can't pass a converter for bidirectional binding, as far as I'm aware, so it works only with properties of the same type.