GarbageCollector.collect()

What's on your mind for Thanksgiving Ibrahim?

This Thanksgiving, I did the usual excessive eating on Thanksgiving, with 2 weeks of salad. The difference this year being, I ate the salad two weeks before Thanksgiving. There was no debt to be paid, it was paid for in advance.

When it comes to public toilets there's two primary operating models. Each person flushes after they use it, or, by necessity each person flushes before they use it. Flushing after using it is courteous, and it's responsible. The person who makes the mess cleans it up. Flushing before is robust. You're not dependent on the courtesy of those before you, of the cleaners, etc. That flushing addresses the personal need to have a clean space.

Memory management comes in these flavors too.

In Java, C#, you have "(memory) managed" code. You allocate as much memory as you need, and a janitor comes to clean it up. You can have circular references, and all sort of weird structures, but at some point they get cleaned up. Eventually, someone will come and ask for more memory than available, and a "flush" happens, to clean up enough space for the new task to run. Or it fails with an OutOfMemoryException.

In C, you manage your own memory. You call malloc to get memory. You call free to "flush" it. If some part of the code, forgets to clean up after themselves, you have a "memory leak", things slow down, and eventually crashes.

In life, flushing after pops up a lot.

Say taxes are "almost due", but you have "no time" to do it. Somehow, magically, April 13th, things that seemed really important are now put on hold, and the taxes get done.

This is the power of deadlines, it provides a counter pressure to everything else that "holds on" your time, and hasn't cleaned up after themselves.

Vacations do this too, things that seemed so very important, can actually wait while your in Spain for two weeks.

They force GC.Collect on your time.

My fridge works likes this too. At some point, I load up on groceries, and at that point I discover old leftovers to discard.

Where relying on GC.Collect is reactive, intentionally calling free/delete is proactive. Just like how computers run slow when you have too many tabs open, having too many claims on your time or attention  slows everything down.

Being super proactive on cleaning up, can be very demanding. But forcing the occasional cleanup (PostGres Vacuum, GC.Collect, Writer.flush, Marie Kondo, etc) has always made space for me to jump into new things.

Courteously flushing for my future self