[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: subclassing

Hi,
       Class CustomLabel extends Label{
         ....
         ....
            public void disposeCard(){
		this.removeMouseListener(eventclass);
		this.removeMouseMoveListener(eventclass);	
		this.setImage(null);	
		this.dispose();
	    }	
       }

Is this method can successfully remove all OS dependecies?.or for removing
all dependencies and a clean delete for my label,what i have to do?.

plz care to share ur thoughts..

thanks in adv 

basha      


Veronika Irvine wrote:

> > Also Important>>>>
> > Even if you continue with the CustomLabel subclass, you will still need
> > to override releaseWidget() to dispose of the image you created when the
> > widget goes away. Don't forget to do super.releaseWidget() too.

> Overriding releaseWidget is not the recommended way to free the image.  You
> should add a Dispose listener to the widget and in the dispose callback,
> call setImage(null) and release the image in the dispose callback.



> "Richard L. Kulp" <richkulp@xxxxxxxxxxxxxxxxx> wrote in message
> news:bfoqm5$2uq$1@xxxxxxxxxxxxxx
> > If what you are doing is adding listeners or changing icons, it might be
> > better to have your "CustomLabel" be a factory extending Object instead.
> > The factory method could then just create a standard label, set the
> > image, add the listeners, etc. This is actually the intention with SWT,
> > that you compose together using the standard widgets rather than
> > subclassing. Often that is all you need.
> >
> > If the "CustomLabel" needs further interaction, then you would save the
> > created Label in an instance variable of the "CustomLabel" factory and
> > in other methods access this label and do things to it. So this factory
> >   actually now becomes a controller because it stays around and
> > continues to interact with the label.
> >
> > Important>>>
> >
> > In your create method that creates the label you must add a dispose
> > listener to it. This is so that the image you allocate in makeIcon can
> > be disposed when the label goes away. If you don't do this you will leak
> > resources.
> >
> > Also Important>>>>
> > Even if you continue with the CustomLabel subclass, you will still need
> > to override releaseWidget() to dispose of the image you created when the
> > widget goes away. Don't forget to do super.releaseWidget() too.
> >
> > Rich
> >
> >