Boehm garbage collector

The automatic garbage collection by Hans Boehm, Alan Demers and Mark Weiser is a conservative garbage collection for C and C . Conservative garbage collection are used by many C or C programs and in a variety of runtime environments for other languages ​​such as the GNU Compiler for Java ( GCJ ), Portable.NET, LLVM, the GNU D compiler and mono (up to version 2.5 ) was used.

The reference implementation supports multiple operating systems including many Unix-like (Linux, Mac OS X, ... ), and Windows and provides a number of advanced features such as incremental and parallel cleanup and a series of different types Finalisierungen. It has been ported with minor changes for the D programming language and is part of the default runtime library Phobos Digital Mars D compiler. It also includes a C library for handling strings called cords. The implementation is subject to a free software license similar to the X11 license.

Garbage collection can also be used in a test mode, which is still the de-allocation of memory manually and is reviewed here is whether it works properly in order to detect memory leaks and double deal locations.

Example

The method works with most unmodified C programs simply by each of the call to malloc () by GC_malloc () and realloc () is replaced by GC_realloc ( ) and removed free () calls. Below standing code section shows the use of the Boehm method instead of the conventional malloc () and free () in C.. Garbage collection is based on the living object references are identified based on an analysis of the stack. This is not possible by portable C code, but requires for each system platform specific customizations.

# include # include # include   int main ( void) {      int i;        GC_INIT ();      for (i = 0; i < 10000000; i)      {          int ** p = (int **) GC_MALLOC ( sizeof (int *) );          int * q = (int *) GC_MALLOC_ATOMIC ( sizeof ( int) );            assert ( * p == 0);          * p = (int *) GC_REALLOC (q, 2 * sizeof ( int) );          if ( i % 100000 == 0)              printf (" Heap size = % d \ n", GC_get_heap_size ());      }        return 0; } Web Links

  • Homepage Overview of the Implementation

Swell

  • Memory management
  • Library (programming)
  • Free programming tool
  • C ( programming language)
  • C

Pictures of Boehm garbage collector

135825
de