Friday, August 01, 2003


Stupid Garbage Collection.

For the love of God, if you're a library writer, never call System.gc().  If you call it, you don't have any fucking clue what you are doing.  I mean it.  Say, when you call that function, how long is it going to take?  The answer is...YOU DON'T KNOW.  Are you running in a big app?  A little app?  One that's had its garbage collection finely tuned?  Are there millions of objects or just a few thousand?

YOU DON'T KNOW. So don't call it.  Ever.  Want your finalizers to run?  Tough shit.  Don't call System.gc().  Maybe your finalizers will never run.  Too bad.  If they must run, put the cleanup operation on a proper queue, set up a thread to check it, and do the work explicitly. 

There is precisely one place to make this kind of decision -- at deployment time.  In certain very limited circumstances, an application deployer might decide that in a given situation, it is sensible to run System.gc() at certain times.  This can usually be done with scripting or some other kind of facility that is built into the app.

I am tired of being bitten by "libraries" that think they need to make deployment decisions.


11:39:52 AM