Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Posssible memory leak in OpenGL Intel Win7 drivers


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
36 replies to this topic

#21 Martins Mozeiko   Crossbones+   -  Reputation: 1422

Like
0Likes
Like

Posted 14 February 2012 - 05:22 PM

What I described should work using Visual C++ and g++ as well. I don't know about the embedded systems, so thanks for clarifying.


Not for me...
c:\test>cat a.cpp
#include <stdio.h>
int main()
{
  int* ptr;
  printf("%p\n", ptr);
}
c:\test>g++ a.cpp

c:\test>a.exe
7EFDE000

c:\test>cl a.cpp /nologo
a.cpp
c:\test\a.cpp(5) : warning C4700: uninitialized local variable 'ptr' used

c:\test>a.exe
00000001

c:\test>


Sponsor:

#22 Yours3!f   Members   -  Reputation: 1397

Like
0Likes
Like

Posted 14 February 2012 - 05:30 PM


What I described should work using Visual C++ and g++ as well. I don't know about the embedded systems, so thanks for clarifying.

It works on neither Visual C++ nor g++. Or, rather, it works for the very same reason that your unmapped buffer appeared valid; undefined behavior. Try, for example, to enable optimization and see that happens.


I use kdevelop which uses cmake and by default sets optimization to -O3, I tried in both debug and release mode, both works. Again it shouldn't.

#23 Yours3!f   Members   -  Reputation: 1397

Like
0Likes
Like

Posted 14 February 2012 - 05:32 PM

try this:

#include <stdio.h>
int* ptr;
int main()
{
printf("%p\n", ptr);
}



#24 Brother Bob   Moderators   -  Reputation: 8631

Like
0Likes
Like

Posted 14 February 2012 - 05:39 PM

try this:

Primitives at global scope are always default initialized to zero. At function scope, they are not.

#25 Yours3!f   Members   -  Reputation: 1397

Like
0Likes
Like

Posted 14 February 2012 - 05:46 PM


try this:

Primitives at global scope are always default initialized to zero. At function scope, they are not.


I know, that's why replied it. but lets return to the topic now. solving the memory leak...

#26 mhagain   Crossbones+   -  Reputation: 8284

Like
0Likes
Like

Posted 14 February 2012 - 05:48 PM

int *ptr, MSVC 2008, debug build, value of 0x0018f668.

Just because it works on one person's machine using a specific compiler does not make it globally valid. The C/C++ standard is quite explicit that uniitalized pointers are undefined. That means that the compiler is largely free to do whatever it wants with them; it may give a value of 0, it may set to random garbage, and that random garbage may or may not point to somewhere valid in memory.

If you're in the habit of doing this, and of relying on it, please remind me to never use any software you write.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#27 Yours3!f   Members   -  Reputation: 1397

Like
0Likes
Like

Posted 14 February 2012 - 06:01 PM

If you're in the habit of doing this, and of relying on it, please remind me to never use any software you write.


I always clean up any warning the compiler gives, and this includes uninitialized variables. So that kind of thing isn't going to happen ever in software I write.

#28 Martins Mozeiko   Crossbones+   -  Reputation: 1422

Like
0Likes
Like

Posted 14 February 2012 - 07:20 PM

But you define all your pointer variables global, not local?

#29 Yours3!f   Members   -  Reputation: 1397

Like
0Likes
Like

Posted 14 February 2012 - 07:44 PM

But you define all your pointer variables global, not local?


why did you think that? I just wanted to show you a case where an uninitialized pointer actually is initialized. That was all.
I didn't imply that I use only global variables...

#30 Yours3!f   Members   -  Reputation: 1397

Like
0Likes
Like

Posted 14 February 2012 - 07:47 PM

@mshafey

gDEBugger has some nice memory leak tracking features, you should check it out

#31 Martins Mozeiko   Crossbones+   -  Reputation: 1422

Like
0Likes
Like

Posted 14 February 2012 - 11:23 PM

why did you think that? I just wanted to show you a case where an uninitialized pointer actually is initialized. That was all.
I didn't imply that I use only global variables...

Previously you said, I'm quoting: "and pointer declaration depends on the compiler (but you are right it should be undefined)". But Now you say they are initialized...

How can "uninitialized pointer" be actually "initialized". There is no such thing as global unitialized variable from users point of view. C standard requires all global variables to be initialized to 0 or by calling C++ constructor.

#32 mshafey   Members   -  Reputation: 102

Like
0Likes
Like

Posted 15 February 2012 - 10:15 AM


Thanks for the suggestion. I've tried your code, it works, but it doesn't fix the leak. I'm still seeing memory leaking at the same rate on the affected platforms.

That's interesting. Let's try to pin down which call is causing it. What happens if you comment out the glTexSubImage2D call? And if you comment out the glMapBuffer block (but leave glTexSubImage2D in and coming from the PBO)?


gDEBugger with the code I posted in the first post. Upon application exit it says "Checking for memory leaks - Context 1 deleted. Memory Leak: 2 object(s) are leaked in GL Context 1 [Leak Size: 2,400KB]". Here are Process Explorer graphs for the original code running for a few minutes.

GPU graph: http://i.imgur.com/KgXix.png
Performance graph: http://i.imgur.com/bD9RH.png

I took out glMapBuffer()/glUnmapBuffer() block. Leak persists. Same for the glTexSubImage2D() call. Took them both out and still. Which lead me to remove everything except just basic calls to draw a rectangle switching colors. I'm sorry I sent everyone in the wrong direction here. It seems like even the most basic GL code causes Windows 7 machines to leak memory. I trimmed it down to this and it still leaks.


void paintGL();
void timerCallback(int value);
void changeSize(int w, int h);

unsigned char c = 255;

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(300, 300);
	glutInitWindowSize(640, 480);
	int windowHandle = glutCreateWindow("Window");
	glutDisplayFunc(paintGL);
	glutReshapeFunc(changeSize);
	timerCallback(0);
	glutMainLoop();
	glutDestroyWindow(windowHandle);
	return 0;
}

void paintGL()
{
	c = c? 0 : 255;
	glColor3ub(c, c, c);
	glBegin(GL_QUADS);
	{
		glVertex3f(-1, 1, 0);
		glVertex3f(1, 1, 0);
		glVertex3f(1, -1, 0);
		glVertex3f(-1, -1, 0);
	}
	glEnd();

        glutSwapBuffers();
}

void changeSize(int w, int h)
{
	glViewport(0, 0, w, h);
}

void timerCallback(int value)
{
	glutPostRedisplay();
	glutTimerFunc(5, timerCallback, 0);
}


I might add that in some runs, this code starts off at about 18 MB and goes up to and then stabilizes at 40 MB in a 5-6 minutes.

#33 vNeeki   Members   -  Reputation: 194

Like
0Likes
Like

Posted 15 February 2012 - 11:56 AM

Hi.

Could it be an issue with GLUT ?

This part :
void timerCallback(int value)
{
        glutPostRedisplay();
        glutTimerFunc(5, timerCallback, 0);
}


Shouldn't be :
int main(int argc, char **argv)
{
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
        glutInitWindowPosition(300, 300);
        glutInitWindowSize(640, 480);
        int windowHandle = glutCreateWindow("Window");
        glutDisplayFunc(paintGL);
        glutReshapeFunc(changeSize);
        glutTimerFunc(5, timerCallback, 0);
        glutMainLoop();
        glutDestroyWindow(windowHandle);
        return 0;
}

void timerCallback(int value)
{
        glutPostRedisplay();
}


?

Edited by vNeeki, 15 February 2012 - 11:59 AM.


#34 mshafey   Members   -  Reputation: 102

Like
0Likes
Like

Posted 15 February 2012 - 12:07 PM

No. I'm finding the same behavior with QGLWidget (not using GLUT). Also, VLC with OpenGL output seems to have this memory increase problem as well.

#35 Yours3!f   Members   -  Reputation: 1397

Like
0Likes
Like

Posted 15 February 2012 - 02:03 PM



Thanks for the suggestion. I've tried your code, it works, but it doesn't fix the leak. I'm still seeing memory leaking at the same rate on the affected platforms.

That's interesting. Let's try to pin down which call is causing it. What happens if you comment out the glTexSubImage2D call? And if you comment out the glMapBuffer block (but leave glTexSubImage2D in and coming from the PBO)?


gDEBugger with the code I posted in the first post. Upon application exit it says "Checking for memory leaks - Context 1 deleted. Memory Leak: 2 object(s) are leaked in GL Context 1 [Leak Size: 2,400KB]". Here are Process Explorer graphs for the original code running for a few minutes.

GPU graph: http://i.imgur.com/KgXix.png
Performance graph: http://i.imgur.com/bD9RH.png

I took out glMapBuffer()/glUnmapBuffer() block. Leak persists. Same for the glTexSubImage2D() call. Took them both out and still. Which lead me to remove everything except just basic calls to draw a rectangle switching colors. I'm sorry I sent everyone in the wrong direction here. It seems like even the most basic GL code causes Windows 7 machines to leak memory. I trimmed it down to this and it still leaks.


void paintGL();
void timerCallback(int value);
void changeSize(int w, int h);

unsigned char c = 255;

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(300, 300);
	glutInitWindowSize(640, 480);
	int windowHandle = glutCreateWindow("Window");
	glutDisplayFunc(paintGL);
	glutReshapeFunc(changeSize);
	timerCallback(0);
	glutMainLoop();
	glutDestroyWindow(windowHandle);
	return 0;
}

void paintGL()
{
	c = c? 0 : 255;
	glColor3ub(c, c, c);
	glBegin(GL_QUADS);
	{
		glVertex3f(-1, 1, 0);
		glVertex3f(1, 1, 0);
		glVertex3f(1, -1, 0);
		glVertex3f(-1, -1, 0);
	}
	glEnd();

		glutSwapBuffers();
}

void changeSize(int w, int h)
{
	glViewport(0, 0, w, h);
}

void timerCallback(int value)
{
	glutPostRedisplay();
	glutTimerFunc(5, timerCallback, 0);
}


I might add that in some runs, this code starts off at about 18 MB and goes up to and then stabilizes at 40 MB in a 5-6 minutes.


This is crazy... I can't believe Intel drivers are this bad on windows... Well I ran into similar problems on windows when I worked for a company for the last summer, and eventually I had to switch to DirectX because the OGL functions just didn't work as expected (or caused crashes etc.)

#36 mhagain   Crossbones+   -  Reputation: 8284

Like
3Likes
Like

Posted 15 February 2012 - 04:13 PM

On reconsidering this, memory usage starting low, followed by an increase then stabilize is probably nothing to be worried about. It's where the stabilize part doesn't happen that you need to start worrying (that's a real leak - stabilization isn't a leak, it's just using resources). What's actually happening would be internal driver behaviour so we're reduced to guessing here, but going by your final stripped down program a reasonable and plausable guess would be that the driver is buffering up geometry used by immediate mode calls - it may for example be writing them into a dynamic VBO and then issuing real draw calls behind the scenes from that.

As for the two leaked objects - I have a suspicion which a simple test will help confirm. If you totally strip down the program so that each frame is nothing more than a clear and swapbuffers, and if they still leak, then I'm going to suggest that they might be your backbuffer and depth buffer (these do exist as actual GPU objects although OpenGL doesn't really expose them as such) - 640 * 480 * 4 * 2 is very close to the reported leak size of 2.4 mb (if my other guess is correct then the increase/stabilize usage pattern should also go away with this strip down). Of course, if gDEBugger allows you to drill further into this and identify which objects were leaked then it would be additional useful info.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#37 mshafey   Members   -  Reputation: 102

Like
0Likes
Like

Posted 16 February 2012 - 09:54 AM

On reconsidering this, memory usage starting low, followed by an increase then stabilize is probably nothing to be worried about. It's where the stabilize part doesn't happen that you need to start worrying (that's a real leak - stabilization isn't a leak, it's just using resources). What's actually happening would be internal driver behaviour so we're reduced to guessing here, but going by your final stripped down program a reasonable and plausable guess would be that the driver is buffering up geometry used by immediate mode calls - it may for example be writing them into a dynamic VBO and then issuing real draw calls behind the scenes from that.


Thanks. We realized this is true. From here:

Memory Usage

It seems to be common to think that there is a memory leak in the OpenGL driver. Some users write simple programs such as this


glClear(...);
SwapBuffers(...);

and they observe that their memory usage goes up each time their Display function is called. That is normal. The driver might allocate some memory space and since the driver is basically a black box, we don't know what it is doing. The driver might be doing some work at optimizing in a secondary thread or preparing some buffering area. We don't know what it is doing, but there is no memory leak.


The problem is, in our application we're dealing with many OpenGL contexts at once (up to 30). For Windows XP on the same hardware, OpenGL memory is small compared to Windows 7. So in a day my application memory goes up to 1.5 GB on Win 7, but stays at 500 MB on XP.

We'll either require more memory or reduce the number of contexts used.

Thanks for the useful input everyone.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS