|[Databinding] db-related objects lifecycle and (listeners) management [message #336125]
||Sat, 23 May 2009 09:11
| Gaetan Minet
Registered: July 2009
I have a few questions about databinding-related objects lifecycle and
I'm working with the databinding framework as included in 3.4
In all snippets, samples and tutorials about databinding I ever read, the
authors never call dispose() on the Bindings (directly or indirectly
calling databindingContext.dispose() as a convenience).
When the observed's lifecycle is short and related to the DBC lifecycle,
as in all
these examples, this probably is not a problem, but with long-lived
objects like datasources, as far as I can see this stacks orphan listeners
in the model object.
Shouldn't the examples include a call to dispose() as a best-practise
anyway, even if in their limited scope this has no implication ?
Also, as expected, Binding implementations don't dispose their target
observable when disposed themself, but do remove their listener on the
It seems only the ObservableValues implementations (like
JavaBeanObservableValue and EObjectObservableValue) have code in
firstListenerAdded/lastListenerRemoved that in turn removes their own
listeners from their target when necessary. On List, map and sets
observable implementations, couldn't this also create orphan listeners in
the same examples, as Observables are created on the fly and never
externally disposed in these examples ?
Worse, ComputedObservableMap (and hence common implementations like
JavaBeanObservableMap) never removes its keyset listener nor any elements
listeners it created during its lifecycle (it doesn't even override
dispose). In common use cases with viewers, when fed with
ObservableListContentProvider.getKnownElements, this is not a problem as
the knownElements Set will be emptied when the
ObservableListContentProvider is disposed() so unhooklistener() will
eventually be called on every element, but with a regular long-lived set
it seems to really stack a ton of orphan listeners, even if we were to
call dispose() on it.
Am I missing something obvious ?
One last minor thing, shouldn't ChangeManager.dispose() call
lastListernerRemoved() as a safeguard too ?
Powered by FUDForum
. Page generated in 0.02226 seconds