Basics: rule of thumb for calling dispose()? [message #331311] |
Sat, 30 August 2008 14:44 |
Eclipse User |
|
|
|
Originally posted by: akarypid.yahoo.gr
Hi,
Is there a rule of thumb for when to call dipose in Eclipse?
I mean, I know that:
1) in SWT, all widgets have a parent and calling dispose() at the root
widget propagates to all children.
2) in JFace data binding, a DataBindingContext is like a widget and you
need to call dispose() in order to release resources.
This is rather ad-hoc though. So is there some basic understanding among
what needs to be disposed? I mean. For instance, does _everything_ that
has a dispose() method need to have that method called? Does
_everything_ that has a parent receive a dispose() call when the
parent's dispose() is called?
For instance, what about Eclipse Forms and FormToolkit class. It has a
parent, but in all examples I've seen it is usually set to a Display
object. But it has no children (the widgets it creates are assigned
specific parents). So it's a little confusing... For instance, which of
the following are correct?:
1) The root widget of the form will dispose of the widgets created by
the toolkit?
2) Is a dispose() call on the toolkit required, or is it enough to just
let it be garbage-collected?
3) Disposing the toolkit has no effect on the widgets it created?
It is rather confusing because the API-documentation says:
"Typically, one toolkit object is created per workbench part (for
example, an editor or a form wizard). The toolkit is disposed when the
part is disposed."
But how does Eclipse know to destroy a FormToolkit that was used to
create an editor? I mean, the constructor for a FormToolkit takes a
Display as a parameter so there's no association to a specific workbench
part...
|
|
|
Powered by
FUDForum. Page generated in 0.03194 seconds