OpenGL not deallocating display list memory
I have an OpenGL app that displays a static scene. This scene is comprised of about 150k polygons. Since there are so many polygons, and since it's a static scene, I decided to use a display list to store all the polygons. It's possible to 'regenerate' the scene while the app is still running.
My problem is that OpenGL doesn't seem to deallocate any of the memory it allocated for the list.
This is where I create the list:
m_displayList = glGenLists(1);
m_polygons = m_generator->polygons(scene_name);
glNewList(m_displayList, GL_COMPILE);
for(int i = 0; i < m_polygons.size(); i++)
{
glBegin(GL_POLYGON);
glNormal3fv(m_polygons[i]开发者_开发知识库->get_normal());
for(int j = 0; j < 4; j++)
{
glColor3fv(m_polygons[i]->get_colors()[j]);
glVertex3fv(m_polygons[i]->get_vertices()[j]);
}
glEnd();
}
glEndList();
Later on, when I want to regenerate the scene, I call this:
glDeleteLists(m_displayList, 1);
That should take care of all the memory OpenGL allocated for the list, correct? As far as I can tell, it isn't. When I generate the scene, my memory usage grows by about 600 Mb, and when I regenerate, it only drops about 30 Mb, before going up another 600 Mb. I figured maybe OpenGL was just being lazy about deleting it, but I can generate scenes until I hit the swap, and nothing ever gets freed.
I know the rest of my application isn't using much. The "generator" class only uses about 30 Mb (that's what's getting deallocated when I regen the scene).
Anyway, I have no idea what I'm doing wrong.
That will free the memory OpenGL allocated for the list. But it won't free any memory YOU allocated.
I don't know how m_generator->polygons(scene_name);
works, but it seems likely that a "generator" might allocate memory to hold the generated data. So check if you should be freeing that.
600 MB sounds like a lot of memory, just guessing but from what I can see 150k polys should only take up about 20 MB in memory. When you create a display list for all these polys, all the data has to be copied to the display list so that would be another 20 MB at least plus other stuff.
Might be a good idea to look through your allocations and see if anything is being over allocated. Just my thoughts.
精彩评论