What, again?
Posted May 2, 2007 1:34 UTC (Wed) by
peterh (subscriber, #4225)
In reply to:
What, again? by bronson
Parent article:
The Rise of Functional Languages (Linux Journal)
Yes, but you have _exactly_ the same problem in a language with explicit deallocation and destructors.
If you use finalizers to free resources, you'll have these sorts of problems. Use a free_my_resources() method for that. If you forget to call it, you'll leak the resources (but the finalizer could check for that, at least limiting the damage). If, on the other hand, you forget to call "delete" on the object, you leak the resources and the object itself. So you have to do something explicit either way, and without garbage collection the damage is worse (you have a memory leak into the bargain).
Not quite sure how that's an improvement, myself.
There is an exception here --- if your object is allocated on the stack (which Java forbids). This does get you a kind of "auto-destruction" semantics. But is this a common case?
(
Log in to post comments)