Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 297950 - CompareEditorInputs are leaked when reusing editors
Summary: CompareEditorInputs are leaked when reusing editors
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Compare (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 3.5.2   Edit
Assignee: Tomasz Zarna CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 288596 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-12-16 06:57 EST by Dani Megert CLA
Modified: 2011-08-12 05:59 EDT (History)
1 user (show)

See Also:
daniel_megert: review+


Attachments
Fix v01 (4.55 KB, patch)
2010-01-07 08:11 EST, Tomasz Zarna CLA
no flags Details | Diff
mylyn/context/zip (66.27 KB, application/octet-stream)
2010-01-07 08:11 EST, Tomasz Zarna CLA
no flags Details
Fix v02 (4.80 KB, patch)
2010-01-07 15:07 EST, Tomasz Zarna CLA
no flags Details | Diff
Fix v02 (for 3.5.2) (4.80 KB, patch)
2010-01-13 06:37 EST, Tomasz Zarna 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 2009-12-16 06:57:49 EST
3.6 M4 but also 3.5.x.

When compare editors are reused (setInput(...) called) then the old compare editor input is not disposed.
Comment 1 Dani Megert CLA 2009-12-16 06:58:12 EST
This should be backported to 3.5.2.
Comment 2 Tomasz Zarna CLA 2009-12-18 09:24:01 EST
Old compare editor inputs were supposed to be disposed as soon as the UI for it gets disposed[1]. This has been broken by adding a check for CompareEditor type (see fix for bug 259411 bullet #5).

[1] org.eclipse.compare.CompareEditorInput.createContents(...).new DisposeListener() {...}.widgetDisposed(DisposeEvent)
Comment 3 Tomasz Zarna CLA 2010-01-05 05:04:43 EST
I broke it, I'll fix it.
Comment 4 Tomasz Zarna CLA 2010-01-07 08:11:26 EST
Created attachment 155492 [details]
Fix v01

The fix reverts logical changes introduced by faulty patch from bug 259411. The misconception in that patch was that the compare editor input is disposed only when editor is closed (so we decided to add a check in the dispose listener and manually dispose the input when disposing the editor). This is obviously wrong, because as Dani reported in this bug, the input should be also disposed when reusing compare editors.

This fix resembles one of the first patches proposed on bug 259411 where I tried to postpone disposing the input until all UI widgets are released by creating a dummy widget and adding a dispose listener to it. That was an ugly hack, so this time the dispose listener is added to the last widget found in the UI structure. Therefore, compare editor input is (always, the faulty check has been removed) disposed at the end making it possible to refer during widgets disposal.

Unfortunately, this is not end of the story. Playing around with the patch I've found two worrying scenarios:
1) Analyzing heap dumps I was able to observe that compare editor inputs are not gc'ed because they are referenced by Editor History even though the editor should not appear in the Editor list when it is closed. I was able to get same results with Eclipse 3.4 so I guess the issue has been there for quite a long time. Moreover, this seems to be more like a bug in the workbench (similar to bug 295046).
2) The second case is much worse. Since 'Use alternative content viewer' feature (bug 201116 and bug 220457) was added after the patch from bug 259411 had been released, switching inputs in the compare editor is based on a faulty disposal implementation. This patch fixes the disposal part but now when switching content viewers 'Widget is disposed' errors are thrown. This must be fixed as well.
Comment 5 Tomasz Zarna CLA 2010-01-07 08:11:50 EST
Created attachment 155493 [details]
mylyn/context/zip
Comment 6 Tomasz Zarna CLA 2010-01-07 08:40:20 EST
In the second scenario we dispose the UI associated with this compare editor input replacing it with a new one, but at the same time we want to keep the input. In other words, the input stays the same, only the UI changes. Afaik, this is something current implementation is not prepared for.
Comment 7 Tomasz Zarna CLA 2010-01-07 15:07:43 EST
Created attachment 155542 [details]
Fix v02

Patch that fixes the issue from comment 6. The compare editor input is disposed only when the top most widget is disposed. The trick with adding a dispose listener to the last widget is still crucial.

Dani, could please you verify if this fixes the leaks? Or were you referring to the compare editor input referenced by Editor History (comment 4, bullet 1)?
Comment 8 Tomasz Zarna CLA 2010-01-11 06:06:51 EST
Fix v02 applied to HEAD, available in builds >N20100110-2000. When verified, I'll release the same fix to the R3_5_maintenance branch.
Comment 9 Dani Megert CLA 2010-01-11 08:38:28 EST
Verified that it fixes the problem from comment 0 but did not review the code in detail.
Comment 10 Tomasz Zarna CLA 2010-01-13 06:37:35 EST
Created attachment 155966 [details]
Fix v02 (for 3.5.2)

The same patch as "Fix v02" adjusted for 3.5.x backporting.
Comment 11 Tomasz Zarna CLA 2010-01-13 06:44:38 EST
"Fix v02 (for 3.5.2)" has been applied to R3_5_maintenance branch, I've also increased the bundle version to "3.5.2.qualifier".
Comment 12 Tomasz Zarna CLA 2011-08-12 05:59:50 EDT
*** Bug 288596 has been marked as a duplicate of this bug. ***