Sign in to follow this  
scottrick49

help with memory leak

Recommended Posts

scottrick49    455
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?

Share this post


Link to post
Share on other sites
swiftcoder    18432
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.

Share this post


Link to post
Share on other sites
scottrick49    455
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.

Share this post


Link to post
Share on other sites
scottrick49    455
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)

Share this post


Link to post
Share on other sites
riruilo    218
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.

Share this post


Link to post
Share on other sites
ma_hty    100
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?

Share this post


Link to post
Share on other sites
scottrick49    455
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;
}

Share this post


Link to post
Share on other sites
scottrick49    455
The rate of memory increase seems to depend on how often the screen is redrawn. Single buffering allows render to be called much more frequently and the memory climbs very fast (1 mb/sec, approximately). With double buffering, it only gets called 60 times a second and the memory climbs at about 4 kb/s or maybe a little slower than that.

Share this post


Link to post
Share on other sites
ma_hty    100
What compiler are you using?
Where you get the glut library?
Is the glut32.dll match the version of the glut library your program linking?

Also, are you sure your testing program contain just the source code you posted?

Share this post


Link to post
Share on other sites
scottrick49    455
I am using Visual C++ 2008 Express Edition.

I am pretty sure I got the glut stuff from nate robins' (sp?) webpage.

I am not sure how to check the glut dll version and the version I am linking against.

I am sure that the code I posted is the only thing being compiled. I can upload the visual studio solution if you wish.

Share this post


Link to post
Share on other sites
ma_hty    100
Please forgive me, I'm always suspicious of Microsoft product.

Is there any chance for you to find a older version Visual C++ to compile and testing your program? (e.g. Visual C++ 6 )

Share this post


Link to post
Share on other sites
scottrick49    455
ugh... i compile with vs2005 on another machine and it does not seem to be happening... I recently bought a new laptop and when I was setting everything up I thought I would try out vs2008 express. It seemed to work well, but maybe there are problems with it?!? I had started working on this project on my old machine using vs2005 (where i just tested this) and I had no memory leaks, so maybe it isn't the code?

Share this post


Link to post
Share on other sites
Sneftel    1788
Quote:
Original post by scottrick49
ugh... i compile with vs2005 on another machine and it does not seem to be happening... I recently bought a new laptop and when I was setting everything up I thought I would try out vs2008 express. It seemed to work well, but maybe there are problems with it?!? I had started working on this project on my old machine using vs2005 (where i just tested this) and I had no memory leaks, so maybe it isn't the code?

It's possible that there's some memory allocation record being kept around. Does the leak happen when you compile and run in Release mode?

Share this post


Link to post
Share on other sites
HuntsMan    368
I can confirm that also leaks in ArchLinux, using :

OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce 8400M GS/PCI/SSE2
OpenGL version string: 2.1.2 NVIDIA 169.07

Also a Dell XPS m1330. Looks like a GLUT or nVidia bug.

Share this post


Link to post
Share on other sites
scottrick49    455
Hmm so doesn't sound like there is anything I can do except just live with it. This should make it fun tracking down other memory leaks haha. It would also explain why it doesn't happen on my older machine.

Share this post


Link to post
Share on other sites
ma_hty    100
For some reason, I am still using Visual Studio 6 and glut. And, I have never encounter memory leak for such a basic implementation.

If you wanted, I can compile your program and give you the executeable for testing. Hopefully, it can provide some more information about the memory leak.

Share this post


Link to post
Share on other sites
scottrick49    455
It looks like the problem may be related to the driver / glut, since HuntsMan had the same results that I saw, and he has the same m1330 laptop I have. If you want to send me your executable I will run it and see what happens; i will pm you with my email

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this