Bug 167872 - HandleLeak in Font.getFontData()
Summary: HandleLeak in Font.getFontData()
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M4   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2006-12-13 11:05 EST by Martin Forst CLA
Modified: 2007-06-05 16:16 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Forst CLA 2006-12-13 11:05:29 EST
Build ID: M20060921-0945

Steps To Reproduce:
1. Create a small SWT project
2. Open the windows task manager, make the GDI object column visible
3. Add FontData fontData = getFont().getFontData()[0]; to the code
4. Debug to the inserted line, when you step over the GDI object count is incremented but there is no possibility to free the temporary created GDI handle


More information:
The problem is the implementation of getFontData:
	if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
	LOGFONT logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA();
	OS.GetObject(handle, LOGFONT.sizeof, logFont);
	return new FontData[] {FontData.win32_new(logFont, device.computePoints(logFont, handle))};

The handle created by OS.GetObject is not disposed.
Comment 1 Steve Northover CLA 2006-12-13 17:56:26 EST
Here is the description of GetObject() from the MSDN:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_912s.asp

Comment 2 Steve Northover CLA 2006-12-13 17:57:37 EST
GetObject() doesn't create a HANDLE.  Can you reopen this bug report with some sample code that is leaking? (a small, stand alone SWT snippet?)
Comment 3 Martin Forst CLA 2006-12-14 02:10:25 EST
Sorry I didn't have a further look on what GetObject does. I did some debugging with the SWT source. The problem is not GetObject but the function Device.computePoints which is called by getFontData. Take a look on the source code:

float computePoints(LOGFONT logFont, int hFont) {
	int hDC = internal_new_GC (null);

internal_new_GC calls GetDC(0) which creates a windows device context and therefore creates a GDI object - which can be seen in the task manager. This device context is not freed by computePoints.
Comment 4 Steve Northover CLA 2006-12-14 11:43:09 EST
Great catch!!!  This code was introduced recently so the leak is new to Eclipse 3.3 M4.
Comment 5 Steve Northover CLA 2006-12-14 11:45:54 EST
Fixed > 20061214  (NOTE:  The fix will be in Eclipse 3.3 M4)
Comment 6 Steve Northover CLA 2006-12-14 11:51:17 EST
Thank you so much for finding and reporting this bug.