Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF Databinding] Properly disposing of observables?
[EMF Databinding] Properly disposing of observables? [message #431115] Mon, 29 June 2009 15:26 Go to next message
Andreas Mayer is currently offline Andreas MayerFriend
Messages: 32
Registered: July 2009
Member
Hi,

in one of his enlightening blog posts on the EMF databinding [1] Tom
Schindl warned about memory leaks due to observables, which are not
disposed when they are no longer needed. He also mentioned:

* ObservableManager, which was added in 3.5. It could be used to keep
track of observables in order to dispose them properly. Due to a bug
it's currently unusable, but Tom shows a way to fix it for EMFObservables.

* Observables for SWT dispose themselves when the corresponding widget
is disposed.

* The rule for all other observables: the one who created it has to
dispose it.


As far as I can see, an EObjectObservable listens to the observed
EObject only as long as someone listens to the EObjectObservable itself.
Once the last listener is removed from the observable, it will also
remove its listener from the EObject. This should be enough to avoid
listener leaking if you dispose the DataBindingContext, shouldn't it?

I also wonder, if DataBindingContext could be used instead of
ObservableManager for life cycle management of observables. It already
keeps track of the bindings and thus has a list of all observables which
are directly used in those bindings. And you need one anyway. So if you
could tell DataBindingContext to also dispose of the observables, you
would only have to manually dispose of observables used in computed
values. Or am I missing something?

[1]
< http://tomsondev.bestsolution.at/2009/06/08/galileo-emf-data binding-%E2%80%93-part-3/>
(see "Avoid listener leaking")
--
Andreas
Re: [EMF Databinding] Properly disposing of observables? [message #431128 is a reply to message #431115] Mon, 29 June 2009 20:58 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Andreas Mayer schrieb:
> Hi,
>
> in one of his enlightening blog posts on the EMF databinding [1] Tom
> Schindl warned about memory leaks due to observables, which are not
> disposed when they are no longer needed. He also mentioned:
>
> * ObservableManager, which was added in 3.5. It could be used to keep
> track of observables in order to dispose them properly. Due to a bug
> it's currently unusable, but Tom shows a way to fix it for EMFObservables.
>
> * Observables for SWT dispose themselves when the corresponding widget
> is disposed.
>
> * The rule for all other observables: the one who created it has to
> dispose it.
>
>
> As far as I can see, an EObjectObservable listens to the observed
> EObject only as long as someone listens to the EObjectObservable itself.
> Once the last listener is removed from the observable, it will also
> remove its listener from the EObject. This should be enough to avoid
> listener leaking if you dispose the DataBindingContext, shouldn't it?

The question is who instructs that the last listener of the object is
gone. This is the general listener problem you are having all over (even
with ordinary event listeners in Swing, SWT, ...). Ideally they are
modeled as Weak-Reference but because listeners are expected to get
invoked in the order they are create this is not an option.

>
> I also wonder, if DataBindingContext could be used instead of
> ObservableManager for life cycle management of observables. It already
> keeps track of the bindings and thus has a list of all observables which
> are directly used in those bindings. And you need one anyway. So if you
> could tell DataBindingContext to also dispose of the observables, you
> would only have to manually dispose of observables used in computed
> values. Or am I missing something?

The problem is that the you could feed your Oberserable to multiple
DatabindingContext's so it cann't be the one who is responsible for
disposing it!

Let's see if I can bring in one of Databinding master minds like Boris
and Matt to clear up the situation a bit.

Tom
Re: [EMF Databinding] Properly disposing of observables? [message #431135 is a reply to message #431115] Mon, 29 June 2009 23:31 Go to previous message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
Andreas, see comments below.

Andreas Mayer wrote:
> * ObservableManager, which was added in 3.5. It could be used to keep
> track of observables in order to dispose them properly. Due to a bug
> it's currently unusable, but Tom shows a way to fix it for EMFObservables.

There's actually two bugs, really:
1) ObservablesManager.dispose fails if there is an exception during
disposal of any managed observable.
2) ObservablesManager.runAndCollect is collecting some observables that
are supposed to be internal state for some objects. So when
ObservablesManager disposes them, it causes all sort of unexpected
problems. The solution is to comb through the library and ensure that
internal observables are created in an ObservablesTracker.runAndIgnore
runnable, or (preferably) in a block like this:

ObservableTracker.setIgnore(true);
try {
// create internal observables
} finally {
ObservableTracker.setIgnore(false);
}

> * Observables for SWT dispose themselves when the corresponding widget
> is disposed.

Correct.

> * The rule for all other observables: the one who created it has to
> dispose it.

Correct.

> As far as I can see, an EObjectObservable listens to the observed
> EObject only as long as someone listens to the EObjectObservable itself.
> Once the last listener is removed from the observable, it will also
> remove its listener from the EObject. This should be enough to avoid
> listener leaking if you dispose the DataBindingContext, shouldn't it?

If the observable is implemented properly, yes. However a few
observables register listeners on the model object right away, instead
of waiting for listeners to be registered. In a few cases this can't be
avoided, so it's best to manage these observables and dispose them
explicitly.

> I also wonder, if DataBindingContext could be used instead of
> ObservableManager for life cycle management of observables. It already
> keeps track of the bindings and thus has a list of all observables which
> are directly used in those bindings. And you need one anyway. So if you
> could tell DataBindingContext to also dispose of the observables, you
> would only have to manually dispose of observables used in computed
> values. Or am I missing something?

There are many observables that get created without being used in a
binding in a DataBindingContext. One example of this is using
DataBinding with a TableViewer: you have an IObservableList or
IObservableSet input, and then there is an IObservableMap for every
column in the table. None of these are tracked by the binding context.

ObservablesManager is intended to manage the lifecycle of both
observables and bindings.

Hope this helps,

Matthew
Previous Topic:Select using BooleanOCLCondition Question!
Next Topic:Generated interfaces
Goto Forum:
  


Current Time: Thu Apr 25 17:22:45 GMT 2024

Powered by FUDForum. Page generated in 0.03313 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top