Boehm garbage collector explained

Boehm–Demers–Weiser Garbage Collector
Other Names:bdwgc
Author:Hans-Juergen Boehm
Developer:Ivan Maidanski, et al.
Latest Release Version:8.2.4
Programming Language:C
Genre:garbage collector
License:similar to X11 (free software)

The Boehm–Demers–Weiser garbage collector, often simply known as the Boehm GC or Boehm collector, is a conservative garbage collector for C and C++ developed by Hans Boehm, Alan Demers, and Mark Weiser.[1] [2]

Boehm GC is free software distributed under a permissive free software licence similar to the X11 license. The first paper introducing this collector appeared in 1992.[3]

Design

Hans Boehm describes the operation of the collector as follows:

Boehm GC can also run in leak detection mode[4] in which memory management is still done manually, but the Boehm GC can check if it is done properly. In this way a programmer can find memory leaks and double deallocations.

Boehm GC is also distributed with a C string handling library called cords. This is similar to ropes in C++ (trees of constant small arrays), but instead of using reference counting for proper deallocation, it relies on garbage collection to free objects. Cords are good at handling very large texts, modifications to them in the middle, slicing, concatenating, and keeping history of changes (undo/redo functionality).

Operation

The garbage collector works with most unmodified C programs, simply by replacing with calls, replacing with calls, and removing calls. The code piece below shows how one can use Boehm instead of traditional malloc and free in C.[5]

  1. include
  2. include
  3. include

int main(void)

For completeness, Boehm supports explicit deallocation via .[6] All the substitution can be done using preprocessor macros.

Uses and ports

The Boehm GC is used by many projects[7] that are implemented in C or C++ like Inkscape, as well as by runtime environments for a number of other languages, including Crystal, the Codon high performance python compiler,[8] the GNU Compiler for Java runtime environment, the Portable.NET project, Embeddable Common Lisp, GNU Guile, the Mono implementation of the Microsoft .NET platform (also using precise compacting GC since version 2.8), GNUstep optionally, and libgc-d[9] (a binding to libgc for the D programming language, used primarily in the MCI). It supports numerous operating systems, including many Unix variants (such as macOS) and Microsoft Windows, and provides a number of advanced features including incremental collection, parallel collection and a variety of finalizer semantics.

External links

Notes and References

  1. Hans Boehm, A garbage collector for C and C++
  2. [Andrew W. Appel]
  3. H. J. Boehm and D. Chase, "A Proposal for Garbage-Collector-Safe C Compilation", The Journal of C Language Translation, Volume 4 Number 2 December 1992, pages 126-141
  4. http://www.hboehm.info/gc/leak.html Using the Garbage Collector as Leak Detector
  5. http://www.hboehm.info/gc/simple_example.html Using the Garbage Collector: A simple example
  6. Web site: Garbage Collector Interface . www.hboehm.info.
  7. https://github.com/ivmai/bdwgc/wiki/Known-clients Known BDWGC uses
  8. Web site: Exaloop/Codon . .
  9. https://github.com/lycus/libgc-d libgc-d