help with memory leak

Started by
19 comments, last by scottrick49 16 years, 1 month ago
Hi, I am trying to track down a memory leak, and I am not sure what the problem is. I have tracked down the problem to a simplified version of my render function, but I do not know why it is leaking memory. Simply clearing the color and depth buffers and then swapping them is leaking memory.

void Render()
{
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
        glutSwapBuffers();
}
Also, here is the line I use to initialize the display.

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
Any suggestions?
scottrick49
Advertisement
I remember old nVidia drivers having a GL memory leak when swapping buffers. See if it occurs without double-buffering.
The code you have posted there does not have a memory leak, at least not one that anyone will be able to diagnose without access to your machine. GLUT is widely enough used (and old enough) that a widespread memory leak in such an essential function would quickly be found using google.

Can you post the full source (in [ source ] tags) to the smallest, complete program that demonstrates the problem? Also your video card and OpenGL driver version would be helpful.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Here -
#include <iostream>#include <GL/glut.h>using namespace std;void Display();void LoopFunction();void Render();unsigned int i = 0;void Display(){	}void InitializeGlut(int argc, char** argv){	glutInit(&argc, argv);	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);	glutInitWindowPosition(100, 100);	glutInitWindowSize(400, 400);	glutCreateWindow("hatfat");	glutDisplayFunc(Display);	glutIdleFunc(LoopFunction);}void LoopFunction(){ //only printing so my computer doesn't lock up as bad	printf("%d\n", i);	i++;	Render();}int main(int argc, char **argv){	InitializeGlut(argc, argv);	glutMainLoop();	return 0;}	void Render(){	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 	glutSwapBuffers();}

This example bogs down my computer, but if you watch the task manager the memory skyrockets.
scottrick49
Also:

NVIDIA GeForce 8400M GS

Main Driver: nvd3dum.dll, nvwgf2um.dll
Version: 7.15.0011.5669
Date: 10/4/2007

I am using a Dell m1330 laptop, and as far as I know, this is the latest version of the video driver.

OpenGL Version 2.1.1 (as returned by glGetString(GL_VERSION)
scottrick49
this is driving me crazy; anybody have an idea?
scottrick49
Try to remove this:

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("hatfat");
glutDisplayFunc(Display);
glutIdleFunc(LoopFunction);

And write this:

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("hatfat");
glutDisplayFunc(LoopFunction);
//glutIdleFunc(LoopFunction);

BTW, you have to do glclear and draw whatever in glutDisplayFunc.

Hope this helps you.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
In Your Idle Loop, change the call Render() to glutPostRedisplay()

-- Edit Typo
Rob Davies - Programmer @ [XWired Games]
Quote:Original post by scottrick49
This example bogs down my computer, but if you watch the task manager the memory skyrockets.


How rapid the memory usage increase? Can you describe it more clearly?
Thanks for the replies. I have modified it so that it uses glutPostRedisplay() instead of calling the render function itself. It still has a memory leak. Also, changing the idle function to be the display function is not something I want to do, since it changes how my program operates.

Here is what I was just testing:
#include <iostream>#include <GL/glut.h>using namespace std;void Display();void LoopFunction();unsigned int i = 0;void Display(){	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 	glutSwapBuffers();}void InitializeGlut(int argc, char** argv){	glutInit(&argc, argv);	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);	glutInitWindowPosition(100, 100);	glutInitWindowSize(400, 400);	glutCreateWindow("hatfat");	glutDisplayFunc(Display);	glutIdleFunc(LoopFunction);}void LoopFunction(){ //only printing so my computer doesn't lock up as bad	printf("%d\n", i);	i++;	glutPostRedisplay();}int main(int argc, char **argv){	InitializeGlut(argc, argv);		const GLubyte *pVersion = glGetString(GL_VERSION);	printf("VERSION = %s\n", pVersion);	glutMainLoop();	return 0;}
scottrick49

This topic is closed to new replies.

Advertisement