Jump to content
  • Advertisement
Sign in to follow this  
McZ

OpenGL OpenGL leaking memory?

This topic is 4579 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just checked in the taskmanager and there I could see that my graphics engine increase 4kb of memory every second. But I can't find any code of mine that leaks (I have no new/delete in render loop). I comment out almost everything in the renderloop so now it looks like this:
void CEngineCore::execute()
{
	MSG msg;
	while(1)
	{
		if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);

			if(msg.message == WM_QUIT)
				break;
		}
		else
		{
			// Render a single frame
			drawFrame();
		}
	};
}

// This is all I have in drawFrame, the rest is commented out.
void CEngineCore::drawFrame()
{
	// Start new frame
	m_pSurface->beginFrame();


	// ... code here commented out

	// end frame
	m_pSurface->endFrame();
}

void CWindowSurfaceGL::beginFrame()
{
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void CWindowSurfaceGL::endFrame()
{
	SwapBuffers(m_hDC);
}

This is all my engine does in the renderloop but still it increase the memory with 4kb it takes every second. if I comment out beginFrame() and endFrame() it doesn't eat my memory.

Share this post


Link to post
Share on other sites
Advertisement
I once had a very dumb OpenGL memory leak: everytime I drew a texture, I uploaded it again to video memory (while it already was in there). After a while memory got full because the same texture was many many times in there, and it became extremely slow, then crashed. Make sure you don't do this same mistake :)

Share this post


Link to post
Share on other sites
I havn't implemented textures yet, just restarted on my new engine. the only thing I draw that I have commented out is a vertexarray with 3 vertices defining a single triangle, no texture and no lights

Share this post


Link to post
Share on other sites
No I don't create the VA every frame.. once at startup (made that mistake once before)

Share this post


Link to post
Share on other sites
I had the same problem at work some times ago. The memory used by our application was slowly growing over time. We found out that simply calling glClear(0) after swapping buffers was solving the problem. However we didn't call glClear anywhere else, so I don't know if it can help you.

Share this post


Link to post
Share on other sites
sebarnolds > Thank you. it works for me too, adding a glClear(0); after SwapBuffers(m_hDC); in endFrame() function results in a no memory leak

Share this post


Link to post
Share on other sites
Glad it helped you.

Now if anybody has an explaination to this, I'm willing to hear it because I don't understand why there is a leak when we don't call glClear().

Besides, we spotted the memory leak when we didn't call glClear at all (because we were drawing on the entire screen). Now it seems you are already calling glClear (at the beginning of the frame) but you have the leak.

I don't think it should have a visible effect on performances, but try to replace the glClear(0) you've just added by the glClear() call you're making in the beginFrame() function and to remove it from the beginFrame() just to see if the leak is still there.

Share this post


Link to post
Share on other sites
I took a look on Google, and it appears a few other people have experienced this too. See here.

I tried to recreate the leak on my own machine, but was unable to. Perhaps its a driver issue?

Share this post


Link to post
Share on other sites
That's interesting. I just checked and my app also grows 6k of memory per second. Same for Quake3. The demos from codesampler.com don't from what I can see. I'll be looking into this issue soon. glClear didn't change anything for me.

What card are you people having? I have an Radeon with latest drivers. Let us know if you have any solutions.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!