Community
Participate
Working Groups
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).
Christof can provide more info.
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.
Dejan or Chris, can someone review/commit? Thanks.
Thanks for agreeing to review Chris!
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.
The problem with sharing FormToolkit is that FormEditor disposes it unconditionally.
(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.
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);
Looks good. Fixed in HEAD.
Fixed in 3.4M2
*** Bug 194776 has been marked as a duplicate of this bug. ***