|
Click here for full text:
Destructors, Finalizers, and Synchronization
Boehm, Hans-J.
HPL-2002-335
Keyword(s): destructors; finalizers; threads; garbage collection
Abstract: We compare two different facilities for running cleanup actions for objects that are about to reach the end of their life. Destructors, such as we find in C++, are invoked synchronously when an object goes out of scope. They make it easier to implement cleanup actions for objects of well-known lifetime, especially in the presence of exceptions. Languages like Java, Modula-3, and C# provide a different kind of "finalization" facility: Cleanup methods may be run when the garbage collector discovers a heap object to be otherwise inaccessible. Unlike C++ destructors, such methods run in a separate thread at some much less well-defined time. We argue that these are fundamentally different, and potentially complementary, language facilities. We also try to resolve some common misunderstandings about finalization in the process. In particular: 1. The asynchronous nature of finalizers is not just an accident of implementation or a shortcoming of tracing collectors; it is necessary for correctness of client code, fundamentally affects how finalizers must be written, and how finalization facilities should be presented to the user. 2. An object may legitimately be finalized while one of its methods are still running. This should and can be addressed by the language specification and client code. Notes: Copyright ACM To be presented at SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 15- 17 January 2003, New Orleans, LA
11 Pages
Back to Index
|