WGL - Memory usage constantly rising

Started by
2 comments, last by karwosts 13 years, 3 months ago
[font=arial, verdana, tahoma, sans-serif][size=2]Hi,

I am considering using OpenGL for a hardware accelerated 2D game, and am writing a Pong clone to familiarize myself with the basics of 2D with OpenGL. Right now I am using straight Win32 and WGL rather than any window/event libraries like GLUT or SDL. However, after getting everything initialized and preparing to start on the game logic, I noticed something interesting happening with the memory usage in Task Manager. Every update (with a normal update speed), the memory usage for Pong.exe has gone up by 4-8 K. I've left the program running for quite some time (3-4 minutes) to see if the problem would correct itself, or if it was just Windows pre-allocating things, but the pattern remained the same.

At the moment the code is little more than creating a window and initializing OpenGL for it, with a simple quad being rendered to ensure that my gluOrtho2D() call worked. Less than 200 lines total. Because of the simplicity of the code, I'd like to figure out what is causing this issue now before adding more stuff and making it more difficult to track down.

My application consists of 3 functions: Render, WndProc, and WinMain.

Render:
void Render()
{
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glVertex2i(0, 0);
glVertex2i(25, 0);
glVertex2i(25, 75);
glVertex2i(0, 75);
glEnd();

SwapBuffers(g_hDC);
}


WndProc handles 3 messages:
  • WM_CREATE -- Stores a device context in a global variable; initializes, chooses, and sets a pixel format descriptor; creates and activates a WGL context; configures OpenGL for 2D rendering; and finally shows the window.
  • WM_CLOSE -- Destroys the window.
  • WM_DESTROY -- Activates a NULL WGL context, deletes the WGL context created in WM_CREATE, releases the device context, and posts a quit message.

Unhandled messages are passed off to DefWindowProc.

WinMain registers a window class, creates a window using that window class, and enters a message loop as follows:
MSG msg;
msg.message = 0;
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0)
{
TranslateMessage(&msg);

DispatchMessage(&msg);
}
else
Render();

}


The message loop is the only loop construct in the code, and--aside from DefWindowProc--Render is the only function that is regularly called in my code.

I have tried making Render do nothing more than glClear and SwapBuffers, and the results are the same. I have tried creating the window class with CS_OWNDC but, as I expected, nothing changed, as I already only call GetDC() once.

I can post the full source for review, but for readability's sake I've only provided the bits that I believe to be relevant at this point.

Any insight that can be provided would be greatly appreciated.
Advertisement
A few days back the same question was asked in this forum, just look into a few older posts. No older then a week.




assainator

"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me


A few days back the same question was asked in this forum, just look into a few older posts. No older then a week.




assainator


Thanks. I guess I didn't catch that because I didn't assume it was a leak.
There's nothing wrong with what you're doing there, I assume it's just windows/graphics driver doing some random stuff. Your code looks fine and you shouldn't lose any sleep over it.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement