[gclist] Are finalizers plus garbage collection inherently sinful?

Patrick C. Beard beard@apple.com
Fri, 8 Mar 1996 14:14:13 -0800


At 9:20 AM 3/7/96, Charles Fiterman wrote:
>Conservative collectors make the safe assumption that
>anything that looks like a pointer is one. It is always
>safe not to delete an object. But if it has a finalizer
>the program is now buggy because that finalizer was not
>called. A good argument for the pricise collection of
>some programs.
>
>If you have a long chain of finalizer dependencies
>the collector will only kill one per collection cycle.
>Since the finalizers are important or they wouldn't be
>there the program is now buggy or takes a really long
>time to terminate.

Another issue along these lines is whether finalizers are guaranteed to be
executed at all before program termination. When using the
Boehm-Weiser-collector, there is no such guarantee. This is especially
important when using the collector in a shared library setting, so that
when a client terminates, all finalizers are eventually called (if
possible, barring constraints of conservativism).

I think the proper conclusion here is that finalization is no substitute
for well designed protocols. Programming languages should include both
garbage collected heaps for objects with unlimited lifetimes, and stack
allocation for objects limited lifetimes. Destructors are perfect for stack
allocated objects, and are executed in a highly predicatable way, which
makes them great for doing things like releasing resources. Finalizers
aren't as useful in this regard, but are necessary for some types of
problems.

- Patrick



--
// Patrick C. Beard, Dynamic Language Engineer
// Developer Products Group, Apple Computer
// beard@apple.com, http://www.bdt.com/home/beard/