Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Disposing of images in composite
Disposing of images in composite [message #277176] Mon, 06 December 2004 08:55 Go to next message
Eclipse UserFriend
Originally posted by: christian.hauser.dvbern.ch

Hello

I have a composite (see code below) that uses two images and a hand
cursor. However, I don't know how to dispose the images and cursor.

I have overwritten the dispose() method of the Widget class, but this
method never gets called. I'm afraid of having a memory leak and would
be very happy if someone could enlighten me on how to dispose of the
images and cursor.

Thanks in advance,

Christian


public class MyComposite extends Composite {

private Image image1 = new Image(Display.getCurrent(),
"./icons/gif1.gif"); //$NON-NLS-1$
private Image image2 = new Image(Display.getCurrent(),
"./icons/gif2.gif"); //$NON-NLS-1$
private final Cursor cursor = new Cursor(getDisplay(), SWT.CURSOR_HAND);

public AboutComposite(Composite parent) {
super(parent, SWT.NONE);
...
}

/**
* @see org.eclipse.swt.widgets.Widget#dispose()
*/
public void dispose() {
image1.dispose();
image2.dispose();
cursor.dispose();
super.dispose();
}
}
Re: Disposing of images in composite [message #277178 is a reply to message #277176] Mon, 06 December 2004 09:17 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,

You should add a dispose listener and do it there.

In case you haven't seen it before, the following "Creating your own
widgets..." article may be of interest to you:
http://eclipse.org/articles/Article-Writing%20Your%20Own%20W idget/Writing%20Your%20Own%20Widget.htm

Grant

"Christian Hauser" <christian.hauser@dvbern.ch> wrote in message
news:cp1obn$2p6$1@www.eclipse.org...
> Hello
>
> I have a composite (see code below) that uses two images and a hand
> cursor. However, I don't know how to dispose the images and cursor.
>
> I have overwritten the dispose() method of the Widget class, but this
> method never gets called. I'm afraid of having a memory leak and would
> be very happy if someone could enlighten me on how to dispose of the
> images and cursor.
>
> Thanks in advance,
>
> Christian
>
>
> public class MyComposite extends Composite {
>
> private Image image1 = new Image(Display.getCurrent(),
> "./icons/gif1.gif"); //$NON-NLS-1$
> private Image image2 = new Image(Display.getCurrent(),
> "./icons/gif2.gif"); //$NON-NLS-1$
> private final Cursor cursor = new Cursor(getDisplay(),
SWT.CURSOR_HAND);
>
> public AboutComposite(Composite parent) {
> super(parent, SWT.NONE);
> ...
> }
>
> /**
> * @see org.eclipse.swt.widgets.Widget#dispose()
> */
> public void dispose() {
> image1.dispose();
> image2.dispose();
> cursor.dispose();
> super.dispose();
> }
> }
Re: Disposing of images in composite [message #277185 is a reply to message #277178] Mon, 06 December 2004 10:08 Go to previous message
Eclipse UserFriend
Originally posted by: christian.hauser.dvbern.ch

> You should add a dispose listener and do it there.
>
> In case you haven't seen it before, the following "Creating your own
> widgets..." article may be of interest to you:
> http://eclipse.org/articles/Article-Writing%20Your%20Own%20W idget/Writing%20Your%20Own%20Widget.htm

Thank you Grant, that works fine.
Previous Topic:eclipse developer plans for compatibilty with cvs 1.12.9
Next Topic:FieldEditorPreferencePage changes
Goto Forum:
  


Current Time: Fri Jul 25 18:57:27 EDT 2025

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

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

Back to the top