Bug 200690 - [Forms] Investigate resource sharing for section header gradients
Summary: [Forms] Investigate resource sharing for section header gradients
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: User Assistance (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M2   Edit
Assignee: Adam Archer CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
: 194776 (view as bug list)
Depends on:
Blocks: 202316
  Show dependency tree
 
Reported: 2007-08-21 10:34 EDT by Dejan Glozic CLA
Modified: 2007-11-02 10:38 EDT (History)
2 users (show)

See Also:
agarcher: review? (cgold)


Attachments
patch (6.61 KB, patch)
2007-09-05 14:52 EDT, Adam Archer CLA
no flags Details | Diff
patch (14.96 KB, patch)
2007-09-07 17:52 EDT, Adam Archer CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dejan Glozic CLA 2007-08-21 10:34:54 EDT
From Andre:

While doing some handle/memory leak tracking, we found that every section header allocates an image for the gradient. Since we use quite a few section headers in the work item editor, it would bring our handle count down if the images could be shared.

In addition we would like to share the FormToolkit (since it allocates resources that can be shared too).
Comment 1 Dejan Glozic CLA 2007-08-21 10:36:21 EDT
Christof can provide more info.
Comment 2 Adam Archer CLA 2007-09-05 14:52:57 EDT
Created attachment 77750 [details]
patch

Added an internal class, org.eclipse.ui.internal.forms.widgets.FormImages. This class is responsible for supplying gradient images through the FormImages.getGradient(...) method, reusing them when appropriate and tracking the number of references to a given image. When a client of FormImages is done with an image it calls FormImages.markFinished(Image) rather than disposing it directly. Once all clients have indicated that they are finished with a given image, FormImages will dispose it and remove any remaining references.

Currently, the only client of this new class is Section. A future enhancement will be to use FormImages for FormHeading gradients as well. I will open a separate bug for that.

Note, with respect to sharing of the FormToolkit in comment 0, that this is already possible. It is up to the client to instantiate a single FormToolkit and keep a reference to it. This toolkit can then be used throughout the appropriate Display and disposed of only once all users of it are finished.
Comment 3 Adam Archer CLA 2007-09-05 14:55:08 EDT
Dejan or Chris, can someone review/commit? Thanks.
Comment 4 Adam Archer CLA 2007-09-05 15:43:48 EDT
Thanks for agreeing to review Chris!
Comment 5 Chris Goldthorpe CLA 2007-09-05 19:19:34 EDT
I like the fact that you have created a new class to cache the gradients. One benefit of this is that it is easy to write JUnit tests for this class which will make it bulletproof. One suggestion I have is to use the singleton pattern to reduce the number of static objects to two. Apart from that the code looks good.

I'll let you decide for yourself if you want to make FormImages a singleton but it definitely needs JUnits, once I have those I can commit for you.
Comment 6 Christof Marti CLA 2007-09-06 03:06:00 EDT
The problem with sharing FormToolkit is that FormEditor disposes it unconditionally.
Comment 7 Adam Archer CLA 2007-09-06 11:21:45 EDT
(In reply to comment #5)
Chris, those are both excellent ideas. I will make it a singleton and will begin work on JUnits today.

(In reply to comment #6)
> The problem with sharing FormToolkit is that FormEditor disposes it
> unconditionally.

So it does. This is a very good point, but a separate bug that should be fixed rather than providing toolkit sharing by default. I have opened a new bug for this. See bug 202474.
Comment 8 Adam Archer CLA 2007-09-07 17:52:01 EDT
Created attachment 77925 [details]
patch

Made FormImages a singleton and added JUnit tests for it.

Usage is now as follows:

FormImages.getInstance().getGradient(...);
FormImages.getInstance().markFinished(Image);
Comment 9 Chris Goldthorpe CLA 2007-09-07 18:32:20 EDT
Looks good. Fixed in HEAD. 
Comment 10 Chris Goldthorpe CLA 2007-09-07 18:32:56 EDT
Fixed in 3.4M2
Comment 11 Dejan Glozic CLA 2007-11-02 10:38:26 EDT
*** Bug 194776 has been marked as a duplicate of this bug. ***