Friday, April 28, 2006


Imagine there is no Image#isDisposed....

Michael Valenta and I were talking today about the Eclipse Image management story and I thought I might post a quick pointer here.

So when do you want an ImageRegistry and when do you want a ResourceManager? First off you want to use either of them to prevent the need to manage Images yourself - you can reference your Images using an ImageDescriptor or a String and let the ResourceManager clean them up when it shuts down.

The ImageRegistry allows you to register an image based on a keyword (String), the ResourceManager allows you to do so with an ImageDescriptor. The ResourceManager is the back end of the ImageRegistry. Usually you use the ImageRegistry to allow lookup based on a constant (like we do for the JFace Dialog constants) and you use the ResourceManager to do lookup based on an ImageDescriptor you are holding onto.

Many people just use the the JFace ImageRegistry or ResourceManager. That will work but if everyone did that large applications will have every image loaded for the duration of thier Eclipse session (those images are generally not disposed until shutdown of JFace). The DeviceResourceManager that JFace uses has reference counting which will cut down on some of the redundant Images but you might be surprised at the references you have if you are not thinking about it.

If you can bound the lifecycle better (especially if you are one of the cool kids who really do dynamically load and unload plug-ins) using your own LocalResourceManager parented off of the JFace one is a great way to keep your OS resource load down.

Doing that will make Stefan Xenos (the ResourceManager mastermind) almost as happy as getting him that Corvette he lusts after ...

This page is powered by Blogger. Isn't yours?