Real life garbage collection

by Taylor Fausak on

Any computer scientist worth their salt knows about garbage collection. It allows programmers to avoid thinking about throwing away things when they’re done with them. Manual memory management sits at the other end of the spectrum. It forces programmers to say when they’re done with something so the computer can do something else with it. They both have the same goal: a program that doesn’t gobble up memory.

Why would anyone prefer to manually manage memory? The same reason people prefer manual transmissions over automatics. In fact, one of my professors (Glenn Downing) used this exact analogy. With manual memory management (stick shift), you get better gas mileage and performance. You can even do things that are impossible in an automatic, like engine braking. But in an automatic, you don’t have to think about anything. Your mind is free to think about things that aren’t related to the internals of the car.

That’s a solid analogy, and it has served me well. I recently thought of another, more personal, one: I manually manage my stuff; other people let garbage collection handle their stuff.

I regularly go over everything I own, deciding whether or not it’s worthwhile to keep it. If it’s not, I give it away, sell it, or throw it out. No sense in keeping something that’s useless. However, most other people that I know only throw things out when they move, or during spring cleaning. It doesn’t bother them to hang on to something worthless; they can just put it in their closet and forget about it.

But when they do move, it’s a huge deal. They have so much junk that they haven’t thought about in so long that they have a hard time even processing it. Eventually they’ll probably give up and put it in a box regardless. It may stay in a box until the next time they move.

Either you have to stop the world every now and then to clean things up, or you have to keep track of things as you go.