Bug 1896 - [Workbench] IWorkbenchPart.dispose called at wrong point in time (1GAUFOO)
Summary: [Workbench] IWorkbenchPart.dispose called at wrong point in time (1GAUFOO)
Status: RESOLVED INVALID
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: All Windows 2000
: P4 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: investigate, needinfo
Depends on:
Blocks:
 
Reported: 2001-10-10 22:21 EDT by Dirk Baeumer CLA
Modified: 2009-08-30 02:10 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2001-10-10 22:21:47 EDT
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.
Comment 1 DJ Houghton CLA 2001-10-24 06:49:16 EDT
PRODUCT VERSION:
	0.033

Comment 2 Kevin Haaland CLA 2002-01-21 19:57:14 EST
This is a really old defect. Do you object to closing it?
Comment 3 Dirk Baeumer CLA 2002-01-22 04:19:44 EST
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.
Comment 4 Dirk Baeumer CLA 2002-01-23 11:23:21 EST
IMO this PR should be fixed sometime but can be postponed after 2.0
Comment 5 Kevin Haaland CLA 2002-01-23 17:49:36 EST
Defering based on feedback from reporter. 
Comment 6 Randy Giffen CLA 2002-08-06 16:06:25 EDT
Reopened for investigation
Comment 7 Kevin Haaland CLA 2003-02-07 13:39:16 EST
There are no plans for the UI team to work on this defect report until higher 
priority items are addressed.  
Comment 8 Tod Creasey CLA 2006-04-13 15:09:06 EDT
I think this is obsolete.
Comment 9 Andy Czerwonka CLA 2006-10-20 09:45:12 EDT
(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.
Comment 10 Denis Roy CLA 2009-08-30 02:10:48 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.