Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » should I dispose of a font when...
should I dispose of a font when... [message #448028] Mon, 27 December 2004 06:45 Go to next message
Liam Morley is currently offline Liam MorleyFriend
Messages: 47
Registered: July 2009
Member
So far, I've been assigning a value to a font and disposing of the font
when I dispose of the parent object. However, I'm about to change the
font while the object is still around- should I dispose of the old font
before reassigning the new font?

For example, in the following basic class structure, should I call
"font.dispose()" in the changeFont method?

MyClass {
private Font font;
public MyClass() {
Font font = ...;
}

public void changeFont(FontData fd) {
// should I call font.dispose() here?
font = new Font(null, fd);
}

protected void widgetDisposed() {
// called from dispose listener
font.dispose();
}
}

Many thanks.

--
Liam Morley
Computer Science Undergraduate
Worcester Polytechnic Institute
Re: should I dispose of a font when... [message #448147 is a reply to message #448028] Mon, 03 January 2005 18:21 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Yes you should. You created the font so you need to dispose of it when
no longer needed.

Liam Morley wrote:
> So far, I've been assigning a value to a font and disposing of the font
> when I dispose of the parent object. However, I'm about to change the
> font while the object is still around- should I dispose of the old font
> before reassigning the new font?
>
> For example, in the following basic class structure, should I call
> "font.dispose()" in the changeFont method?
>
> MyClass {
> private Font font;
> public MyClass() {
> Font font = ...;
> }
>
> public void changeFont(FontData fd) {
> // should I call font.dispose() here?
> font = new Font(null, fd);
> }
>
> protected void widgetDisposed() {
> // called from dispose listener
> font.dispose();
> }
> }
>
> Many thanks.
>

--
Thanks,
Rich Kulp
Previous Topic:To dispose or not to dispose
Next Topic:Why are SWT.SHIFT and SWT.RIGHT detected as duplicated in switch-case loop.
Goto Forum:
  


Current Time: Thu Apr 18 23:04:54 GMT 2024

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

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

Back to the top