How delete a display list quick and clean?

Hi there!

I’m working on a software project, which contains several Open/GL operations. One of the functions generates many display lists, e.g. like this:

int displayList = glGenLists(10);
// ** Mark **
glNewList(displayList + 0, GL_COMPILE);
drawNodes();
glEndList();
glNewList(displayList + 1, GL_COMPILE);

These lists allocate a huge ammont of memory, everytime this function is called (which is quiet often). So I tried to delete the lists before they are generated with this piece of code, standing instead of the line

 "// ** Mark **":

for (int i=0;i<10;i++) 
{glDeleteLists(displayList + i, 1);}

But for some reason the allocated mem is still growing, everytime I run through this function. How can I free the mem again?

Thank you in advance.

I don’t think you should call glDeleteLists in a for loop. If the display list numbers are sequential then just call glDeleteLists( displayList, range). Where “range” is the number of lists you generated. Look up the glDeleteLists function for an exact definition.

Also, if more memory is used every time you compile a new list, it may be because you are drawing more nodes every time as well (putting to much in lists, there is a limit afterall). If this is not the case, then it may be that you were not deleting them properly.

in that case my question is: How do I delete them properly so that there is nothing left of them?

glDeleteLists will delete them properly if you use the function properly. You had to have called glGenLists to allocate the names (id numbers) for the lists. Then glNewList is used to store the rendering data in a named (id number) display list. glDeleteLists will delete all of the list names (plus stored rendering data) that glGenLists allocated (if used correctly). Also, according to the specs, if you call glNewList again with a display list ID you used previously (and have not deleted), then it will replace that display list. So, I speculate that you could delete the rendering data (without deallocating the name…see glDeleteLists) by simply calling glNewLists and glEndList right away. Then that display list name (id number) will contain no rendering data.

Sorry for the long winded answer, but the manual specification for glGenLists, glNewList and glDeleteLists contain better and more precise information.

Good Luck,

Sorry, I looked at your code more carefully this time.

Remove all your list deleting code and replace it with this (not including quotes).

“glDeleteLists( displayList, 10);”

That will delete all the lists you allocated memory for.