Bug 229483 - SWT Color leak originating from ToolbarEditPart.java
Summary: SWT Color leak originating from ToolbarEditPart.java
Status: RESOLVED FIXED
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy GEF (MVC) (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.4.0 (Ganymede) RC1   Edit
Assignee: Cherie Revells CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2008-04-29 17:23 EDT by Richard Mah CLA
Modified: 2008-09-18 13:41 EDT (History)
2 users (show)

See Also:


Attachments
Screen shot of Sleak showing the 2 leaked Color objects (44.07 KB, image/pjpeg)
2008-04-29 17:23 EDT, Richard Mah CLA
no flags Details
Screencap of ToolBarEditPart.java and the code which creates the leaked Color objects. (17.91 KB, image/pjpeg)
2008-04-29 17:24 EDT, Richard Mah CLA
no flags Details
Proposed fix. (14.05 KB, patch)
2008-05-02 11:29 EDT, Cherie Revells CLA
ahunter.eclipse: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Mah CLA 2008-04-29 17:23:44 EDT
Created attachment 98081 [details]
Screen shot of Sleak showing the 2 leaked Color objects

I'm seeing a Color leak when using GMF based editor with a palette.  The leak is being detected with the use of Sleak.  Everytime I close the editor, I see an increase of 2 for the Color objects.

The Color being leaked appears to be the Color returned as a result of mixing PaletteColorUtil.WIDGET_BACKGROUND and PaletteColorUtil.WIDGET_NORMAL_SHADOW.  See below.
See ToolbarEditPart:
            graphics.setForegroundColor(FigureUtilities.mixColors(
                PaletteColorUtil.WIDGET_BACKGROUND,
                PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.7));

I've poked around with the ToolbarEditPart code and ensured I disposed of the mixed Color object in the deactivate() method.  When this is done, I don't see the leak.

Please see the two screenshots I will attach.
Comment 1 Richard Mah CLA 2008-04-29 17:24:52 EDT
Created attachment 98082 [details]
Screencap of ToolBarEditPart.java and the code which creates the leaked Color objects.
Comment 2 Cherie Revells CLA 2008-04-30 14:05:27 EDT
According to the discussion in Bug 68979 I do not need to dispose Colors.
Comment 3 Anthony Hunter CLA 2008-05-01 13:18:47 EDT
(In reply to comment #0)
> I'm seeing a Color leak when using GMF based editor with a palette.  The leak
> is being detected with the use of Sleak.  Everytime I close the editor, I see
> an increase of 2 for the Color objects.

Does this mean after you open and close the editor 4 times you have 8 Color objects? Or do you only have 2? 
Comment 4 Richard Mah CLA 2008-05-01 13:33:33 EDT
(In reply to comment #3)
> (In reply to comment #0)
> > I'm seeing a Color leak when using GMF based editor with a palette.  The leak
> > is being detected with the use of Sleak.  Everytime I close the editor, I see
> > an increase of 2 for the Color objects.
> Does this mean after you open and close the editor 4 times you have 8 Color
> objects? Or do you only have 2? 

I would have 8 Color objects.  I've also noticed an increase of 5 Color objects with the following scenario:
1)Open the editor (the palette will be shown)
2)Hide the palette
3)Reshow the palette
4)Close the editor
If I run through the above scenario 4 times, I see a total increase of 20 Color objects.
Comment 5 Cherie Revells CLA 2008-05-02 11:29:20 EDT
Created attachment 98445 [details]
Proposed fix.

I have moved all the calls in the new Palette code where new Colors are created with FigureUtilities to the PaletteColorUtil class and declared them as static so that only one Color object will only ever be created for each of these.

Anthony -- this is ready for review.

FYI -- There is a bugzilla open against SWT to clarify whether new Colors need to be disposed or not.  See Bug 164051.
Comment 6 Randy Hudson CLA 2008-05-08 12:41:40 EDT
Colors are not resources and do not need to be disposed.  There is a bugzilla open against Sleak requesting that it filter our Colors:  bug 164026.
Comment 7 Anthony Hunter CLA 2008-05-08 15:26:46 EDT
Committed to HEAD