View Full Version : BoundsChecker Resource Leak

03-29-2004, 07:33 PM
I recently ran my source through BoundsChecker to help identify any mem leaks.

It listed my OpenGL window's HDC as a resource leak. Specifically "Resource Leak Exiting Program" although I verified that ReleaseDC gets called on the way out.

I use the same code for creating and destroying windows and the only one that shows up as a leak is the OpenGL window that I create an RC for (in addition to the DC).

Here is what I am doing:

hwnd = CreateWindowEx( ... )
hdc = GetDC( hwnd )
hrc = wglCreateContext
wglMakeCurrent( hdc, hrc )

wglMakeCurrent( NULL, NULL )
wglDeleteContext( hrc )
ReleaseDC( hwnd, hdc )

Any clue what I'm missing with this issue?

Thank you.

03-30-2004, 05:43 PM
Hmmm, from what I can see here, everything looks good to me. The problem may not be your code. It could just be BoundsChecker. Programmer's aren't always perfect...

03-30-2004, 06:56 PM
Thank you for the quick response. That is what I am beginning to think as well.

03-30-2004, 10:50 PM
I don't know if this is worth it but,
usually when creating a window and registering a class you would specify to create a private DC for the window(in the RegisterClass call: CS_OWNDC). Even though the WIN32 API docs explicitly says do not delete DC's retrieved from GetDC this might be a special case. You can try changing ReleaseDC to DeleteDC and see if it makes BoundsChecker happy.

03-30-2004, 11:45 PM
IMHO its bad practice to ignore return values.

So you may want to check if your wgl* calls fail or succeed.

04-01-2004, 03:55 PM
Thank you both for the responses.

roffe: Yes, I always use OWNDC when creating a windows for OpenGL, just to be safe. I'll try the Delete DC call.

Honk: I am checking for errors, just didn't put that in the pseudo code above for simplicity. No wgl errors reported back.