Reputation: 2352
In my freeglut project, i have allocated alot of memory, and i have no ways to free that when users close freeglut (or glut) window, any ideas?
Upvotes: 2
Views: 4491
Reputation: 1568
Register an exit function with atexit(onexit) before the main loop.
Upvotes: 2
Reputation: 12927
FreeGLUT offers several solutions to that:
You can call glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION)
and glutLeaveMainLoop()
to make glutMainLoop()
function return, and then you can free all the memory you want after glutMainLoop()
call.
Instead of calling glutMainLoop()
you can make your own event loop like this:
bool running = true;
while (running)
{
glutMainLoopEvent();
}And whenever you want to exit application - just set running variable to false, and free the allocated memory after while loop.
Or you can do nothing - any modern OS correctly deallocates all the allocated memory when process terminates. Of course, if you need do some special thing on termination - like write to log file, send network packets, then you must manually do that.
Upvotes: 8