Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 334402 - Image provider not releasing cached image descriptors when the diagram editor is closed
Summary: Image provider not releasing cached image descriptors when the diagram editor...
Status: CLOSED FIXED
Alias: None
Product: Graphiti
Classification: Modeling
Component: Core (show other bugs)
Version: 0.8.0   Edit
Hardware: All All
: P4 normal (vote)
Target Milestone: 0.9.0   Edit
Assignee: Tim Kaiser CLA
QA Contact:
URL:
Whiteboard: Juno M1 theme_bugs
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-14 12:36 EST by Shenxue Zhou CLA
Modified: 2012-06-28 10:38 EDT (History)
2 users (show)

See Also:
michael.wenz: juno+


Attachments
mylyn/context/zip (1.05 KB, application/octet-stream)
2011-06-22 04:01 EDT, Tim Kaiser CLA
no flags Details
mylyn/context/zip (2.09 KB, application/octet-stream)
2011-06-22 04:04 EDT, Tim Kaiser CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Shenxue Zhou CLA 2011-01-14 12:36:27 EST
Currently, an image provider registered to a diagram type is not released when the corresponding diagram editor is closed. This is implemented for performance reason since it's expensive to cache the image data.

But the downside of this implementation is memories for the images are not released when the editor is closed thus causing memory leaks. Since we cannot predict whether the user is likely to re-open the same editor again or not in the future, we should adhere to the good programming practice of releasing all the memories when a program exits.
Comment 1 Shenxue Zhou CLA 2011-01-14 12:40:38 EST
Forum discussion can be found at http://www.eclipse.org/forums/index.php?t=tree&th=202971&start=0&S=71fe419cf8a542ec682b3ccd58198a86
Comment 2 Tim Kaiser CLA 2011-06-21 05:34:26 EDT
Shenxue,

i had a look at the issue. The ImageProvider only has a string to string
map between image keys and path strings. It is the Graphiti UI Plugin's 
image registry that handles the images. Indeed they are kept until the SWT Display goes away. But also the JavaDoc of the Image Registry states the following:
"Because of this, clients do not 
need to (indeed, must not attempt to) dispose of these images themselves."

It is hard for us to know when to dispose the images centrally.

An easy solution would be to offer a method "removeImageFromRegistry" in the Graphiti's ImageService
which calls the remove method of ImageRegistry to dispose the image.
This method can be invoked by clients of the framework when they know that their image is not in use anymore to free space.

What do you think? Would this suffice to solve your use-case?

Otherwise we would have to change the whole design and affect existing customers and cause API changes (have an image provider per editor and not centrally etc)

Best, Tim
Comment 3 Tim Kaiser CLA 2011-06-21 11:20:04 EDT
..also we should think about the drawback of having one image registry per editor:
if we open several editors of the same type we allocate the same image several times....
Clearly, an advantage would be that all images are gone if all editors are closed but this can be an disadvantage, too: you cannot use the images somewhere else in the UI, since their lifecycle would be tied to the lifecycle of the editor.
Comment 4 Shenxue Zhou CLA 2011-06-21 12:02:41 EDT
(In reply to comment #2)
> Shenxue,
> 
> i had a look at the issue. The ImageProvider only has a string to string
> map between image keys and path strings. It is the Graphiti UI Plugin's 
> image registry that handles the images. Indeed they are kept until the SWT
> Display goes away. But also the JavaDoc of the Image Registry states the
> following:
> "Because of this, clients do not 
> need to (indeed, must not attempt to) dispose of these images themselves."
> 
> It is hard for us to know when to dispose the images centrally.
> 
> An easy solution would be to offer a method "removeImageFromRegistry" in the
> Graphiti's ImageService
> which calls the remove method of ImageRegistry to dispose the image.
> This method can be invoked by clients of the framework when they know that
> their image is not in use anymore to free space.
> 
> What do you think? Would this suffice to solve your use-case?
> 
> Otherwise we would have to change the whole design and affect existing
> customers and cause API changes (have an image provider per editor and not
> centrally etc)
> 
> Best, Tim

Yes adding removeImageFromRegistry method to the ImageService would solve my problem. When I dispose my editor, I can call that. Thanks!
Comment 5 Tim Kaiser CLA 2011-06-22 04:01:27 EDT
Created attachment 198373 [details]
mylyn/context/zip
Comment 6 Tim Kaiser CLA 2011-06-22 04:04:39 EDT
I checked in the mentioned method.
Can you verify that it works as desired?
Comment 7 Tim Kaiser CLA 2011-06-22 04:04:42 EDT
Created attachment 198375 [details]
mylyn/context/zip
Comment 8 Shenxue Zhou CLA 2011-06-22 12:51:28 EDT
Tim,

After spending some time with Graphiti's ImageService and ImageProvider, it seemed to me there is one more missing piece in removing image caches when the diagram editor is closed. AbstractImageProvider class doesn't provide an API to remove image file paths from its own cache. When diagram editor is closed, the image file path caches in AbstractImageProvider aren't cleared either. 

Could you provider an API in AbstractImageProvider to remove image file path cache? That method can do two things: clear the image file path cache and call removeImageFromRegistry() on ImageService to remove the image data cache.

Does that make sense?

Thanks,

Shenxue
Comment 9 Tim Kaiser CLA 2011-06-28 04:24:46 EDT
Shenxue,

i also had a look at that. But the current design does not allow us
to remove the image file paths. Observe that the image file paths
are initialized in the constructor. If we remove them, they will 
never come back ;-)

We would have to change the whole image provider setup (API changes). Do you see severe consequences if we stick to the current setup?

Best, Tim
Comment 10 Shenxue Zhou CLA 2011-07-11 15:46:00 EDT
(In reply to comment #9)
> Shenxue,
> 
> i also had a look at that. But the current design does not allow us
> to remove the image file paths. Observe that the image file paths
> are initialized in the constructor. If we remove them, they will 
> never come back ;-)
> 
> We would have to change the whole image provider setup (API changes). Do you
> see severe consequences if we stick to the current setup?
> 
> Best, Tim

I can work around this problem by checking whether the image file path has been registered before I add image file path to the cache. Thanks for looking into this.
Comment 11 Michael Wenz CLA 2011-07-14 08:20:36 EDT
Marked as part of Juno
Comment 12 Michael Wenz CLA 2012-04-11 10:29:33 EDT
Bookkeeping: Set target release
Comment 13 Michael Wenz CLA 2012-06-28 10:38:49 EDT
Part of Graphiti 0.9.0 (Eclipse Juno)