[gclist] Finalization and death notices
Thomas F. Burdick
tfb@OCF.Berkeley.EDU
Mon, 8 Oct 2001 23:31:47 -0700
Jerrold Leichter writes:
> | This seems to come back to the same old debate about GC for
> | C++ -- to finalize or not to finalize, and if so how? We
> | go round and round looking for the "right" way, whereas java
> | just went ahead and did it wrong, and users soon learned
> | that finalizers were nearly useless. And lacking destructors
> | they learned to manage resources with finally clauses.
>
> Which actually brings us back to a fundamental point that gets lost in too
> much of the discussion of C++, destructors, and finalizers: The fundamental
> difference between lexically and dynamically determined lifetimes.
>
> When C++ programmers complain that finalizers don't run immediately, what they
> usually have in mind is the "initialization is resource acquisition" (hence,
> the "destruction is resource deacquisition") idiom. However, this idiom
> really only makes sense for stack-allocated objects. Like a finally clause,
> IRA/DRD deals with the need to clean up resources that live only in a
> lexically defined scope - but a scope with multiple exits, often because of
> the possibility of exceptions escaping the scope. No one has proposed using
> gc for stack-allocated objects - and if a compiler can determine the lexical
> lifetime of a heap-allocated object, it can certainly arrange to have it
> deleted directly, without gc involvement.
Actually, you're talking about dynamic extent versus indefinate
extent, not lexical vs dynamic scope.