Bug 419692 - Java Type Indicator decorator causes image leak
Summary: Java Type Indicator decorator causes image leak
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.4 M3   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords: greatbug
Depends on:
Blocks:
 
Reported: 2013-10-17 07:36 EDT by Niraj Modi CLA
Modified: 2013-10-31 05:09 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Niraj Modi CLA 2013-10-17 07:36:57 EDT
This bug was reported in bug 402983 comment 21
https://bugs.eclipse.org/bugs/show_bug.cgi?id=402983#c21
Comment 1 Paul Webster CLA 2013-10-17 10:41:35 EDT
From the bug:

Investigating the duplicate package visible icons, I was able to reproduce with a fresh Eclipse 4.3.1 SDK, a new workspace and these steps:

1. In the workspace preferences, under General > Appearance > Label Decorations, enable "Java Type Indicator"
2. In the Package Explorer, enable "Link with Editor"
3. Create a new Plug-In Project, accepting all defaults
4. Open the newly created Activator.java
5. Open a package private class file, e.g. org.eclipse.core.internal.adapter.AdapterFactoryProxy
6. For good measure, switch a couple of times between the two editors
7. Take a snapshot in Sleak
8. Switch some more between the editors
9. Show the diff in Sleak

You should see a number of images at the bottom of the list, all copies of the package local class file icon.

I'm sure there's other leaks - or pathes to this one - though, because my Eclipse currently grows by about 1000 images per hour in my productive workspace. I'll keep looking.
Comment 2 Dani Megert CLA 2013-10-18 11:12:31 EDT
That was a tricky one to debug! It turns out that the problem is a missing #equals and #hashCode in InterfaceIndicatorLabelDecorator.TypeIndicatorOverlay. As a result, the resource manager thinks he needs to create a new decorate image every time.
Comment 3 Markus Keller CLA 2013-10-18 13:46:26 EDT
ImageDescriptor doesn't tell that implementations must override equals/hashCode. If all implementation are expected to do this, then this must be documented and added to the migration guide, so that existing implementations can be fixed. Probably affects all DeviceResourceDescriptors.

You can also blame the DecoratorManager for holding on to so many images that are not in use any more -- however, that's hard to fix: DecorationResult#decorateWithOverlays(Image, ResourceManager) calls ResourceManager#createImage(ImageDescriptor), whose Javadoc tells that it leaks unless the resource manager is short-lived or the image is manually destroyed. Neither of these conditions can be satisfied, since the workbench window is long-lived and we have no clue how long the created images will be in use.

Maybe the DecoratorManager could use a special 'lossy' ResourceManager that doesn't use reference counting but wraps the values (created Images) into a WeakReference and calls destroyImage(ImageDescriptor) when an Image becomes weakly reachable, i.e. right when it can be disposed. Though that would remove the 'caching' feature of DecoratorManager for images that are not always in use somewhere.
Comment 4 Dani Megert CLA 2013-10-21 04:57:48 EDT
Same bug is in 3.x as well. I don't think we will make big changes to the decoration story at this point, so, just stating the expected behavior is the practical thing to do here.
Comment 5 Dani Megert CLA 2013-10-30 11:50:02 EDT
Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=a5ed672f97aee794e1e2512ad609484eb3b2409d

Filed bug 420741 for updating the Javadoc.
Comment 6 Dani Megert CLA 2013-10-31 05:09:49 EDT
Verified in I20131030-2000.