Bug 25818 - [Workbench] PageBookView causes editors to leak
Summary: [Workbench] PageBookView causes editors to leak
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0.2   Edit
Hardware: PC Windows 2000
: P1 critical (vote)
Target Milestone: 2.0.2   Edit
Assignee: Nick Edgar CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-11-07 08:42 EST by Dani Megert CLA
Modified: 2002-11-11 04:56 EST (History)
1 user (show)

See Also:


Attachments
First cut of patch - need refinement (1.17 KB, patch)
2002-11-07 10:00 EST, Dani Megert CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2002-11-07 08:42:06 EST
Build 2.0.2 and 2.1


Test Case 1:
Ensure Outline view is visible.
Open 10 Java editors and then close all with the "Close All" action.
==> 9 editors stay in memory.

Test Case 2:
Ensure Outline view is visible.
Open 2 Java editors via Package Explorer
Activated the second editor
Activated the first editor
Press the close box of the second editor without activating it before
Press the close box of the first editor
==> both editors stay in memory

We suspect that PageBookView.partClosed does not dispose the local action bar
and does not remove the listeners for non-active parts.
Comment 1 Dani Megert CLA 2002-11-07 09:13:01 EST
After ensuring that dispose is called on subActionBars in
PageBookView.partClosed and PageBookView.dispose all editors were correctly
removed from memory.
Comment 2 Nick Edgar CLA 2002-11-07 09:41:43 EST
Dani, could you please include the patch you describe in comment #1?
Comment 3 Nick Edgar CLA 2002-11-07 09:42:06 EST
Should fix for 2.0.2.
Comment 4 Dani Megert CLA 2002-11-07 09:56:46 EST
Sure, will be there in a minute, just need to kick off 2.0.2.

NOTE: I only did a quick fix. There's also listeners and other stuff that might
be worth being removed/disposed.
Comment 5 Dani Megert CLA 2002-11-07 10:00:16 EST
Created attachment 2336 [details]
First cut of patch - need refinement
Comment 6 Nick Edgar CLA 2002-11-07 12:17:47 EST
The preferred change is to dispose the action bars in removePage, and change 
partClosed to the following.

public void partClosed(IWorkbenchPart part) {
	// Update the active part.
	if (activeRec != null && activeRec.part == part) {
		showPageRec(defaultPageRec);
	}
	
	// Find and remove the part page.
	PageRec rec = getPageRec(part);
	if (rec != null)
		removePage(rec);
}

However, this has a different order of method invocations.
The current order is:
- dispose the sub action bar of old page
- activate new (default) page

The new order would be:
- deactivate sub action bar contributions for old page
- activate new (default) page
- dispose sub action bar of old page
(this wouldn't cause any extra UI updates though, since the action bars are 
only updated once).

It would be safer to go with Dani's change for 2.0.2.
Comment 7 Dani Megert CLA 2002-11-07 12:31:11 EST
I agree with Nick. I also first thought removePage would be the right place when
I notice the change in control flow.

What about the selection listener? Shouldn't it be removed too? At least the
last page might leak the listener if it wasn't activated, right?
Comment 8 Nick Edgar CLA 2002-11-07 12:56:22 EST
The selection listener is only hooked on the active page, and is removed in 
both partClosed and showPageRec (showPageRec also adds it to the new active 
page).  But it looks like it's not removed in dispose().  I'll have a look.

Or were you thinking of a different case?
Comment 9 Nick Edgar CLA 2002-11-07 13:02:04 EST
It's OK not to unhook the selection listener on dispose, since everything is 
going away: the page book view, its site, all its pages and their sites.
I didn't see any leaks here when profiling this.
Comment 10 Nick Edgar CLA 2002-11-07 16:03:56 EST
Fixed in r202-v20021107a.
Comment 11 Dani Megert CLA 2002-11-08 03:00:03 EST
Nick,

I thought of the following scenario:  I remove the last editor but it was not
active. It would go through partClosed, then not being treated because the part
is not the active one. But I guess this case i.e. no part ever being active -
does not exist, right?

Another issue (though not critical): it seems that the property change listener
on the subActionBar isn't removed.
Comment 12 Dani Megert CLA 2002-11-08 03:18:43 EST
Is there a new PR for the 2.1 stream? I didn't get new code when I catched up
this morning.
Comment 13 Nick Edgar CLA 2002-11-08 09:40:02 EST
I forgot to release it in the 2.1 stream.  I'd prefer to release the fix in 
comment #6 though.  Reopening to do this.
Comment 14 Nick Edgar CLA 2002-11-08 09:40:45 EST
I'll look at the other cases you mention too.
Comment 15 Nick Edgar CLA 2002-11-08 14:46:13 EST
I've applied the change in comment #6 in the HEAD stream.

For the case 1 in comment #11, I tried:
- open A.java
  - selection listener gets added to A's outline page
- open B.java
  - selection listener gets removed from A's outline page
  - selection listener gets added to B's outline page
- close A.java
  - no change to selection listeners
- deactivate B by clicking on Navigator
  - no change to selection listeners (the Navigator does not provide an 
outline, so it still shows B's)
- close B without activating it
  - selection listener gets removed from B's outline page (as far as the 
outline view is concerned, it was still the active page)

So this case looks fine.  Or were you imagining some other scenario?

For case 2, it should not matter if the property change listener is not 
removed, since the SubActionBars instance is being let go.  However, it would 
be cleaner to clear the listener list, in case the SubActionBars is hung onto 
by someone else for some reason.  That way it won't hold a reference to the 
PageBookView.  I've added a propertyChangeListeners.clear() to 
SubActionBars.dispose() (in HEAD stream only).
Comment 16 Nick Edgar CLA 2002-11-08 14:52:32 EST
Note that JavaOutlinePage.dispose() could use fSelectionChangedListeners.clear
() instead of iterating.
Comment 17 Dani Megert CLA 2002-11-11 04:56:27 EST
changed code in JavaOutlinePage.
Thanks for the tip.