memory release

I’m using linked list to save the objects
data (need it for draw the obects each time
some event happens).
Is it legal to free the list after glutMainLoop() ?

if no,what should I do ??
(Note: I need the list because I read the data from a file once).

Thank you.

Sure it’s legal to release the memory after glutMainLoop. Only problem is that glutMainLoop never returns, so you will never get there.

If you exit your program with the exit() function, or something similar, release the memory there instead. Also note that you don’t have to release the memory before exiting. If you don’t do it, the operating system will do it instead, so you don’t get any memoryleaks that way.