Why free memory on application quit?

Sage
Posts: 1,478
Joined: 2002.09
Post: #25
AnotherJake Wrote:That's weird. Like what else besides freeing resources would be appropriate in a destructor?

IO objects are a good example. They close the stream when they are collected. You don't want them to just leave it open because it may be a long time before the program exits.

Now consider that you've built some buffered IO object on top of that. If it was simply allowed to be GCed, it may still have data buffered that hasn't been written to the physical stream. If the stream was to be closed before the buffered data is written to it, it would corrupt the data.

OneSadCookie: Again, I assume it has to do with it being impossible to tell which destructor functions are safe to skip, and which ones aren't.

Back to the original topic. I once thought that it was good practice to free everything before the program quit, but have since come to agree with the consensus here. It doesn't actually benefit anybody, so why bother?

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 


Messages In This Thread
Why free memory on application quit? - Josh - Nov 24, 2008, 09:52 AM
Why free memory on application quit? - sohta - Nov 24, 2008, 10:52 AM
Why free memory on application quit? - sohta - Nov 24, 2008, 11:11 AM
Why free memory on application quit? - sohta - Nov 24, 2008, 11:39 AM
Why free memory on application quit? - sohta - Nov 24, 2008, 02:58 PM
Why free memory on application quit? - sohta - Nov 24, 2008, 04:13 PM
Why free memory on application quit? - macnib - Nov 24, 2008, 05:12 PM
Why free memory on application quit? - Skorche - Nov 24, 2008 11:34 PM
Why free memory on application quit? - Fenris - Nov 25, 2008, 04:16 AM
Why free memory on application quit? - DoG - Nov 25, 2008, 05:38 AM
Why free memory on application quit? - mattz - Nov 25, 2008, 08:56 PM
Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  My game crashes on quit... hangt5 17 7,767 Jan 30, 2005 09:38 PM
Last Post: hangt5
  Carbon Apple quit Event troubles deekpyro 3 5,000 May 7, 2002 06:24 AM
Last Post: deekpyro