skip to main content
article

Destructors, finalizers, and synchronization

Published: 15 January 2003 Publication History

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[8], Modula-3[12], and C\#[6] 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.Languages like Java[8], Modula-3[12], and C\#[6] 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:
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.
An object may legitimately be finalized while one of its methods are still running. This should and can be addressed by the language specification amd client code.

References

[1]
J. J. Bloch. Effective Java Programming Language Guide. Addison-Wesley, 2001.
[2]
H.-J. Boehm. A garbage collector for C and C++. http://www.hpl.hp.com/personal/Hans_Boehm/gc/.
[3]
H.-J. Boehm, R. Atkinson, and M. Plass. Ropes: An alternative to strings. Software Practice and Experience, 25(12):1315--1330, December 1995.
[4]
G. Colvin, B. Dawes, P. Dimov, and D. Adler. Boost smart pointer library. http://www.boost.org/libs/smart_ptr/.
[5]
R. K. Dybvig, C. Bruggeman, and D. Eby. Guardians in a generation-based garbage collector. In SIGPLAN '93 Conference on Programming Language Design and Implementation, pages 207--216, June 1993.
[6]
ECMA. Standard ECMA-334: C# Language Specification. ECMA, December 2001.
[7]
J. R. Ellis and D. L. Detlefs. Safe, efficient garbage collection for C++. Technical Report CSL-93-4, Xerox Palo Alto Research Center, September 1993.
[8]
J. Gosling, B. Joy, and G. Steele. The Java Language Specification, Second Edition. Addison-Wesley, 2000.
[9]
B. Hayes. Finalization in the collector interface. In International Workshop on Memory Management (IWMM 92, LNCS 637), pages 277--298, 1992.
[10]
J. Horning, B. Kalsow, P. McJones, and G. Nelson. Some useful modula-3 interfaces. Technical Report 113, Digital Systems Research Center, December 1993.
[11]
IEEE and The Open Group. IEEE Standard 1003.1-2001. IEEE, 2001.
[12]
G. Nelson, editor. Systems Programming with Modula-3. Prentice-Hall, 1991.
[13]
P. Rovner. On adding garbage collection and runtime types to a strongly-typed, statically-checked, concurrent language. Technical Report CSL-84-7, Xerox Palo Alto Research Center, July 1985.
[14]
B. Stroustrup. The Design and Evolution of C++. Addison-Wesley, 1994.
[15]
Sun Microsystems. Java 2 platform, standard edition, v 1.4.0 api specification. http://java.sun.com/j2se/1.4/docs/api/, 2002.
[16]
G. van Rossum. Python reference manual. http://www.python.org/doc/current/ref/ref.html.

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM SIGPLAN Notices
ACM SIGPLAN Notices  Volume 38, Issue 1
January 2003
298 pages
ISSN:0362-1340
EISSN:1558-1160
DOI:10.1145/640128
Issue’s Table of Contents
  • cover image ACM Conferences
    POPL '03: Proceedings of the 30th ACM SIGPLAN-SIGACT symposium on Principles of programming languages
    January 2003
    308 pages
    ISBN:1581136285
    DOI:10.1145/604131
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 15 January 2003
Published in SIGPLAN Volume 38, Issue 1

Check for updates

Author Tags

  1. deadlock
  2. destructor
  3. finalization
  4. garbage collection
  5. synchronization
  6. thread

Qualifiers

  • Article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)15
  • Downloads (Last 6 weeks)0
Reflects downloads up to 10 Nov 2024

Other Metrics

Citations

Cited By

View all
  • (2022)Programming Transactional MemoryTransactional Memory10.1007/978-3-031-01719-3_2(15-52)Online publication date: 17-Oct-2022
  • (2013)Resco: Automatic Collection of Leaked ResourcesIEICE Transactions on Information and Systems10.1587/transinf.E96.D.28E96.D:1(28-39)Online publication date: 2013
  • (2013)Light-weight resource leak testing based on finalisersIET Software10.1049/iet-sen.2013.00267:6(308-316)Online publication date: 1-Dec-2013
  • (2008)The CLOSERProceedings of the 7th international symposium on Memory management10.1145/1375634.1375636(1-10)Online publication date: 7-Jun-2008
  • (2024)Integrating Data Privacy Compliance in Active Object LanguagesActive Object Languages: Current Research Trends10.1007/978-3-031-51060-1_10(263-288)Online publication date: 29-Jan-2024
  • (2020)Cyber Threat Impact Analysis to Air Traffic Flows Through Dynamic Queue NetworksACM Transactions on Cyber-Physical Systems10.1145/33774254:3(1-22)Online publication date: 12-Mar-2020
  • (2020)On Hiddenness of Moving Target Defense against False Data Injection Attacks on Power GridACM Transactions on Cyber-Physical Systems10.1145/33727514:3(1-29)Online publication date: 12-Mar-2020
  • (2017)Limitations of Partial CompactionACM Transactions on Programming Languages and Systems10.1145/299459739:1(1-44)Online publication date: 6-Mar-2017
  • (2016)Short PaperProceedings of the 2016 ACM Workshop on Programming Languages and Analysis for Security10.1145/2993600.2993604(69-75)Online publication date: 24-Oct-2016
  • (2014)Automatic recovery from resource exhaustion exceptions by collecting leaked resourcesJournal of Zhejiang University SCIENCE C10.1631/jzus.C130035215:8(622-635)Online publication date: 9-Aug-2014
  • Show More Cited By

View Options

Get Access

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media