Disposing of images in composite [message #277176] |
Mon, 06 December 2004 08:55  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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();
> }
> }
|
|
|
|
Powered by
FUDForum. Page generated in 0.29785 seconds