Community
Participate
Working Groups
IWorkbenchPart.dispose is called after the widget tree the part stands for as been disposed. Since this method is supposed to be overriden to free native resources doing so is only possible by remembering all OS resource via fields. You can't write Control control= getControl(); Menu menu= control.getMenu(); <== you get a widget dispose error Why isn't the method called before the widgets are disposed ? NOTES: EG (3/19/01 6:36:24 PM) Isn't this inconsistent with the dispose life cycle in SWT where dispose is called while the widget tree is still alive. DS (4/5/01 2:50:39 PM) WorkbenchPart is not an SWT control. It is a factory for the creation of SWT controls. If the part is closed the workbench uses the SWT dispose mechanism to dispose of those controls. Then it calls dispose on the part to signal the end of its lifecycle. I would argue that this is similar to a JFace viewer. In each case the part / viewer is expected to hook the control dispose and perform any cleanup at that point as required. In this particular scenario a PR has been logged against SWT. The menu for an SWT control should be disposed when the control is disposed, automatically. I have updated the javadoc on IWorkbenchPart to clarify this .. * <p> * After <code>createPartControl</code> has been called, the implementor may * safely reference the controls created. When the part is closed * these controls will be disposed as part of an SWT composite. A part may define * a dispose listener on its own control to free any SWT resources as required. * If the part invokes any method on the disposed SWT controls after this point an * <code>SWTError</code> will be thrown. * </p> * <p> * The last method called on <code>IWorkbenchPart</code> is <code>dispose</code>. * This signals the end of the part lifecycle. * </p> DB (06.04.2001 09:35:19) As far as I know SWT they can't dispose the menu when the control is disposed since you can share a menu between different SWT control (a menu is like a font). Either they must change their menu sharing policy or their dispose policy. Since it is not clear to me that they can fix the PR I would like to reopen it again. Moving to Inbox again. DS (4/10/01 10:16:13 AM) In my previous post I said two things: a) SWT will try to address this. There has been no action so far to dispose of the menu automatically, but they are looking at it. b) Even if the menu problem is not fixed, you can hook dispose events on the control. A dispose event is sent out at the start of the dispose lifecycle .. class Widget { public void dispose () { releaseChild (); // Typically overridden for Composite. releaseWidget (); // Fires event. destroyWidget (); } void releaseWidget () { sendEvent (SWT.Dispose); state |= DISPOSED; eventTable = null; data = null; keys = null; values = null; } } Notice that the event is fired at the start of the lifecycle before the widget has actually been disposed. According to Kevin H it is acceptable to hook the dispose event and clean up any SWT stuff as rrequired, as long as no events are fired as the result of your action. This means you can implement your control using a standard SWT lifecycle and we do not need to change the part lifecycle. DB (10.04.2001 18:14:17) To clarify my point: If I have to hook listeners for all my internal controls since dispose is called when the widgets I have created are "dead" anyway for what purpose can I use the dispose hook. The only way I can see is to keep references to all resource via fields. I don't agree to close this PR since the purpose of a dispose hook is to clean up SWT resources. And this envolves lot of code in the current implementation. DS (4/10/01 12:54:13 PM) The control isn't "dead". It is only about to be "shot", so you can call methods to get the menu, image, etc, from the control directly. DB (10.04.2001 19:00:30) Which control do you mean? I am talking about the control created in IWorkbenchPart.createPartControl(Composite). And this one definitly throws a SWT dispose error when you try to access it. DS (4/12/01 12:39:32 PM) I talked with Dirk about this by phone .. a) He was confused by the term dispose. By the name, he felt that the implementation is expected to dispose of the controls. b) We do need a method to signal the end of the part lifecycle. c) He would prefer to see the introduction of a new method, something like aboutToBeDisposed or disposePartControl. Right now everybody needs to hook the dispose event and this is 15 extraneous lines of code for every part. Then I talked with Kevin about this .. a) Yes, it may be confusing. b) It works as is. Any change would be breaking. c) We may consider this after June.
PRODUCT VERSION: 0.033
This is a really old defect. Do you object to closing it?
But the defect still exists. If you don't want to break existing API, what's about adding a new method that is called before the SWT widget got disposed.
IMO this PR should be fixed sometime but can be postponed after 2.0
Defering based on feedback from reporter.
Reopened for investigation
There are no plans for the UI team to work on this defect report until higher priority items are addressed.
I think this is obsolete.
(In reply to comment #8) > I think this is obsolete. > I dont' think so. How do I register a listener for a dispose event and get it fire before the control is disposed? The standard DisposeListner deals with post disposal only.
As of now 'LATER' and 'REMIND' resolutions are no longer supported. Please reopen this bug if it is still valid for you.