Bug 200337 - [Viewers] ColumnViewerEditor leaks ViewerCell instances.
Summary: [Viewers] ColumnViewerEditor leaks ViewerCell instances.
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.3.2   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-17 06:50 EDT by Chris Simmons CLA
Modified: 2008-02-04 16:58 EST (History)
6 users (show)

See Also:
Mike_Wilson: pmc_approved+
eclipse: review+
bokowski: review+


Attachments
Clearing cell after editor deactivated (1.42 KB, patch)
2007-08-17 08:39 EDT, Thomas Schindl CLA
no flags Details | Diff
Moving nulling at the end (1.47 KB, patch)
2007-09-03 12:16 EDT, Thomas Schindl CLA
no flags Details | Diff
Still leaking when editor activation cancled (6.31 KB, text/x-java)
2008-01-25 11:04 EST, Thomas Schindl CLA
no flags Details
fixing leak when activation cancled (822 bytes, patch)
2008-01-25 11:10 EST, Thomas Schindl CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Simmons CLA 2007-08-17 06:50:53 EDT
Build ID: I20070621-1340

Steps To Reproduce:
The jface class ColumnViewerEditor has a field "cell" of type ViewerCell.  This is set and never unset which can cause problems as the only way to overwrite it is to have a user click on a cell, say (or otherwise open a viewer editor).

I have 3 views showing model A in my RCP app.  If a user clicks on a cell in view 1 then loads model B then this troublesome viewer cell will leek a reference to model B.  I f they then click on a cell in editor 2 and reload model C then I also leek a reference to model B etc.  I can only fit three models in memory at one time and sometimes I need to explicitly load three simultaneously so this is quite debilitating!

This is clearly not a good state of affairs.  Setting the input should reset this field, or it should be made more transient so that, say, it is explicitly nulled when either no cell editor is opened or the cell editor completes editting.

There's a work-around for read-only views, by overriding
ColumnViewer.triggerEditorActivationEvent
to do nothing you can avoid the whole problem.  However, I can't see any way around this problem for views with editors.

Thanks for looking into this :)
Comment 1 Thomas Schindl CLA 2007-08-17 08:21:32 EDT
(In reply to comment #0)
> Build ID: I20070621-1340
> 
> Steps To Reproduce:
> The jface class ColumnViewerEditor has a field "cell" of type ViewerCell.  This
> is set and never unset which can cause problems as the only way to overwrite it
> is to have a user click on a cell, say (or otherwise open a viewer editor).
> 
> I have 3 views showing model A in my RCP app.  If a user clicks on a cell in
> view 1 then loads model B then this troublesome viewer cell will leek a
> reference to model B.  I f they then click on a cell in editor 2 and reload
> model C then I also leek a reference to model B etc.  I can only fit three
> models in memory at one time and sometimes I need to explicitly load three
> simultaneously so this is quite debilitating!
> 

Can you please provide a snippet to reproduce this?

> This is clearly not a good state of affairs.  Setting the input should reset
> this field, or it should be made more transient so that, say, it is explicitly
> nulled when either no cell editor is opened or the cell editor completes
> editting.
> 

Good point. Nulling it out make sense.

> There's a work-around for read-only views, by overriding
> ColumnViewer.triggerEditorActivationEvent

Hm why's that needed. If your Viewer is not editable ColumnViewerEditor.handleEditorActivationEvent() is a no-op anyways not?

> to do nothing you can avoid the whole problem.  However, I can't see any way
> around this problem for views with editors.

Well if that's really the problem you can use reflection to null out the field in the ColumnViewerEditor maybe?

> 
> Thanks for looking into this :)
> 

We are caching ViewerCells in other part of the system too: e.g. ColumnViewer, SWTCellFocusManager
Comment 2 Thomas Schindl CLA 2007-08-17 08:39:24 EDT
Created attachment 76293 [details]
Clearing cell after editor deactivated
Comment 3 Markus Keller CLA 2007-08-27 10:34:16 EDT
(In reply to comment #1)
> We are caching ViewerCells in other part of the system too: e.g. ColumnViewer,
> SWTCellFocusManager

Yes, I frequently see such leaks in TreeViewers (last updated cell is leaked in ColumnViewer#cell, which finally leaks the client's model elements via ViewerCell#element). This makes it hard to find other leaks.

Will you fix all these leaks with this bug, or do you already have another bug for the other leaks?
Comment 4 Thomas Schindl CLA 2007-08-27 10:46:09 EDT
no I'll only address the Editor leak here. Need to put some thought into the other leak in ColumnViewer.
Comment 5 Markus Keller CLA 2007-08-27 11:46:27 EDT
Thanks, filed bug 201280 for the ColumnViewer case.
Comment 6 Kim Horne CLA 2007-08-31 08:48:09 EDT
+1.  Has this been applied to 3.4 yet?
Comment 7 Thomas Schindl CLA 2007-08-31 09:02:29 EDT
No. I wanted to do this in at once
Comment 8 Thomas Schindl CLA 2007-08-31 09:09:12 EDT
Released to R3_3_maintenance >= 20070831
Comment 9 Thomas Schindl CLA 2007-08-31 09:41:46 EDT
3.4 integration is done in bug #201906
Comment 10 Thomas Schindl CLA 2007-08-31 09:42:07 EDT
fixed for 3.3.1
Comment 11 Thomas Schindl CLA 2007-09-03 12:15:35 EDT
Reopened because introduced an NPE
Comment 12 Thomas Schindl CLA 2007-09-03 12:16:49 EDT
Created attachment 77593 [details]
Moving nulling at the end
Comment 13 Boris Bokowski CLA 2007-09-03 16:16:07 EDT
+1
Comment 14 Kim Horne CLA 2007-09-03 18:02:08 EDT
Ping-pong - closing again
Comment 15 Thomas Schindl CLA 2007-09-07 15:15:20 EDT
Verified by code introspection in M20070905-1045
Comment 16 Thomas Schindl CLA 2008-01-25 11:04:28 EST
Created attachment 87873 [details]
Still leaking when editor activation cancled

Still snippet demonstrates that we still leak
Comment 17 Thomas Schindl CLA 2008-01-25 11:10:47 EST
Created attachment 87874 [details]
fixing leak when activation cancled
Comment 18 Thomas Schindl CLA 2008-01-25 11:17:38 EST
The snippet shows that we have missed two cases :-(
Comment 19 Boris Bokowski CLA 2008-01-25 11:21:27 EST
This is a temporary leak, right? Is there a workaround that clients could use?
Comment 20 Thomas Schindl CLA 2008-01-25 11:25:32 EST
well they could access the cell using reflection and null it explicitly before refreshing/setting a new input (if they are the ones who control it).
Comment 21 Tod Creasey CLA 2008-01-25 11:35:15 EST
McQ this might be a 3.2.2 addition
Comment 22 Mike Wilson CLA 2008-01-25 13:34:34 EST
(In reply to comment #18)
> The snippet shows that we have missed two cases :-(
> 
Does that mean "... and there are likely to be more."?

McQ.

Comment 23 Thomas Schindl CLA 2008-01-25 13:38:05 EST
setting to 3.3.2 and moving to Boris
Comment 24 Thomas Schindl CLA 2008-01-25 13:43:21 EST
(In reply to comment #22)
> (In reply to comment #18)
> > The snippet shows that we have missed two cases :-(
> > 
> Does that mean "... and there are likely to be more."?
> 
> McQ.
> 

Not as far as I can see, the problem was that we forgot to clear the cell when we cancled the cell-editor activation. The patch fixes the 2 remaining possibilities for the "leak".
Comment 25 Boris Bokowski CLA 2008-01-25 14:03:42 EST
+1 from me for putting the patch "fixing leak when activation cancled" into 3.3.2.

A better way to deal with this in 3.4 would be to return a boolean from ColumnViewerEditor.activateCellEditor: returns true if a cell editor was activated. Then, the field "cell" could be cleared in just one place, if activateCellEditor returns false, close to where a value is assigned to that field. This would also increase the chances that we won't introduce the leak again when further changes to activateCellEditor are made in the future.

For 3.3.2, I believe Tom's patch is the appropriate fix since it minimizes the number of changed lines of code.
Comment 26 Tod Creasey CLA 2008-01-28 12:19:00 EST
Adding McQ back in for PMC approval for this last change
Comment 27 Tod Creasey CLA 2008-01-28 13:03:43 EST
Final patch released for build >20080128
Comment 28 Boris Bokowski CLA 2008-02-04 16:58:27 EST
Verified on Windows XP using M20080131-1440.