7
\$\begingroup\$

Should a game/engine clean up after itself(close windows, shut down renderers, close files, free memory) when its closed?

The OS should do that anyway, and usually in a faster way.

I guess most developers don't really care as they need proper cleanup for everything anyways(With dynamic asset-loading, and changing maps, etc.), but won't ensure that everything gets cleaned perfectly.

But is there any positive to cleaning up vs not cleaning up or the reverse?

I am using C++.

What about game consoles? Do they all clean up after themselves?

\$\endgroup\$
  • 2
    \$\begingroup\$ This sounds like a programming question. It seems to have been covered on StackOverflow. \$\endgroup\$ – Anko Apr 8 '15 at 19:26
  • 1
    \$\begingroup\$ @Anko Great reference, but for games this might be different, so I guess this has place here. \$\endgroup\$ – akaltar Apr 8 '15 at 19:30
  • \$\begingroup\$ I don't understand why was this put on hold. As you can see in the answers there are game-dev specific answers to this question. (ex: How does this work on game consoles, user experience) \$\endgroup\$ – akaltar Apr 9 '15 at 13:38
  • \$\begingroup\$ Just because there are "game specific" answers does not mean the question is on-topic. Whether or not you should clean up on exit is a general programming question (whether or not you have to on specific game consoles may not be, but would be off-topic here for other reasons, primarily being trivia-based, unless it was accompanied with an actual concrete problem the asker was trying to solve). \$\endgroup\$ – Josh Apr 9 '15 at 15:43
  • \$\begingroup\$ @JoshPetire I can't question your reasoning, but I think the answer to "Can a game developer answer this question better?" is "Yes". \$\endgroup\$ – akaltar Apr 9 '15 at 15:58
9
\$\begingroup\$

Yes, a game/engine should clean up after itself when it's closed. There are good reasons for that:

  • Show to your team that you know what's going on in your game
  • Know when your managers are shut down
  • Make sure your files and handles are closed and your data is saved
  • Help prevent crashes on exit because you have a better idea to what's going on
  • Help find memory leaks: if you clean everything yourself, you should not have any memory leaks, so the next time you use a tool to detect them, it should give you 0 leaks. You'd have a harder time achieving this if you don't clean on shutdown.

And it smells fresher when stuff is clean!

\$\endgroup\$
  • \$\begingroup\$ Seems great rationale for no crash on clean and general good practice, I'll give some time for others before accepting. \$\endgroup\$ – akaltar Apr 8 '15 at 19:29
  • 1
    \$\begingroup\$ I would suggest that whilst all of these are good reasons to, they should come secondary to the user experience. If the player has to suffer through a bad exit experience then being "correct" is all rather academic. \$\endgroup\$ – lzcd Apr 8 '15 at 23:15
  • 3
    \$\begingroup\$ PS3 required a clean shutdown, but 360 didn't. The Wii would essentially reboot between games so wouldn't require it either. Point being, not all platforms do it for you but many do. \$\endgroup\$ – Alan Wolfe Apr 8 '15 at 23:22
0
\$\begingroup\$

if you have used malloc() or similar memory allocation functions then you must use free() to destroy the allocated memory when your done, and similar when you use the new operator to create an instance of something then you must use delete() to destroy it when done, otherwise those resources and memory may still exists or be locked up in the background, so its good practice to de-allocate memory yourself to be safe.

\$\endgroup\$
  • 4
    \$\begingroup\$ This is not true on application exit; all memory used by a process is automatically released by the process when it exits. That's not the general case for all object types however; a good discussion is available here gamedev.net/topic/… \$\endgroup\$ – Maximus Minimus Apr 9 '15 at 7:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.