Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » to be or not to be? is disposing correct?
to be or not to be? is disposing correct? [message #463668] Wed, 14 February 2007 05:13 Go to next message
Eclipse UserFriend
Originally posted by: peter_ossipov.mail.ru

Hello everybody!
I have a class-singleton for my application that manages caching images
in my application. I dispose it this way. Is it correct to do it like
that? Or should I dispose it when the bundle stops?
private ImageMaker()
{
// do not forget to free all the system resources
PlatformUI.getWorkbench().addWorkbenchListener(new
IWorkbenchListener()
{

public void postShutdown(IWorkbench workbench)
{
dispose();
PlatformUI.getWorkbench().removeWorkbenchListener(this);
}

public boolean preShutdown(IWorkbench workbench, boolean forced)
{
return true;
}
});
}

/**
* dispose all cashed images
*
*/
private void dispose()
{
for (Iterator iter = imagesCache.values().iterator();
iter.hasNext();)
{
Image image = (Image)iter.next();
image.dispose();
}
imagesCache.clear();
}
Re: to be or not to be? is disposing correct? [message #463670 is a reply to message #463668] Wed, 14 February 2007 05:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: 11235813.despammed.com

Peter Osipov schrieb:
> Hello everybody!
> I have a class-singleton for my application that manages caching images
> in my application. I dispose it this way. Is it correct to do it like
> that? Or should I dispose it when the bundle stops?

Why don't you use an ImageRegistry instead? Then you don't have to think
about disposing the images by yourself.

Carmen
Re: to be or not to be? is disposing correct? [message #463671 is a reply to message #463668] Wed, 14 February 2007 05:27 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Why don't you simply use ImageRegistry and let it handle the disposing
for you? You can use JFaceResources.getImageRegistry() to even share
your images across plugin boundaries ;-)

Tom

Peter Osipov schrieb:
> Hello everybody!
> I have a class-singleton for my application that manages caching images
> in my application. I dispose it this way. Is it correct to do it like
> that? Or should I dispose it when the bundle stops?
> private ImageMaker()
> {
> // do not forget to free all the system resources
> PlatformUI.getWorkbench().addWorkbenchListener(new
> IWorkbenchListener()
> {
>
> public void postShutdown(IWorkbench workbench)
> {
> dispose();
> PlatformUI.getWorkbench().removeWorkbenchListener(this);
> }
>
> public boolean preShutdown(IWorkbench workbench, boolean forced)
> {
> return true;
> }
> });
> }
>
> /**
> * dispose all cashed images
> *
> */
> private void dispose()
> {
> for (Iterator iter = imagesCache.values().iterator();
> iter.hasNext();)
> {
> Image image = (Image)iter.next();
> image.dispose();
> }
> imagesCache.clear();
> }
Re: to be or not to be? is disposing correct? [message #463672 is a reply to message #463671] Wed, 14 February 2007 05:49 Go to previous message
Eclipse UserFriend
Originally posted by: peter_ossipov.mail.ru

Yep, I thought about it actually. But by the time I found out about this
registry - the current way had been done, so do not want to change to
registry if the current way is OK. Just too much to do apart from
polishing the code. :-)
Tom Schindl wrote:
> Hi,
>
> Why don't you simply use ImageRegistry and let it handle the disposing
> for you? You can use JFaceResources.getImageRegistry() to even share
> your images across plugin boundaries ;-)
>
> Tom
>
> Peter Osipov schrieb:
>
>> Hello everybody!
>> I have a class-singleton for my application that manages caching images
>> in my application. I dispose it this way. Is it correct to do it like
>> that? Or should I dispose it when the bundle stops?
>> private ImageMaker()
>> {
>> // do not forget to free all the system resources
>> PlatformUI.getWorkbench().addWorkbenchListener(new
>> IWorkbenchListener()
>> {
>>
>> public void postShutdown(IWorkbench workbench)
>> {
>> dispose();
>> PlatformUI.getWorkbench().removeWorkbenchListener(this);
>> }
>>
>> public boolean preShutdown(IWorkbench workbench, boolean forced)
>> {
>> return true;
>> }
>> });
>> }
>>
>> /**
>> * dispose all cashed images
>> *
>> */
>> private void dispose()
>> {
>> for (Iterator iter = imagesCache.values().iterator();
>> iter.hasNext();)
>> {
>> Image image = (Image)iter.next();
>> image.dispose();
>> }
>> imagesCache.clear();
>> }
>>
Previous Topic:Integrate log4j in standalone-RCP-Application
Next Topic:Snippets + Undo/Redo
Goto Forum:
  


Current Time: Thu Mar 27 23:51:16 EDT 2025

Powered by FUDForum. Page generated in 0.02879 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top