Go to the first, previous, next, last section, table of contents.


Garbage collecting

Starting with version 0.9.0, libFoundation comes with two garbage collecting mechanisms that provide you with the ability to solve the memory management problem.

The first garbage collector works with the default memory management policy in OpenStep, the reference counting model. Reference counting is a simple model for keeping track of objects and works good enough unless you have cyclic data structures in your program, aka graphs of objects. These cyclic graphs of objects cannot be collected by the normal reference counting mechanism provided by OpenStep Foundation. libFoundation comes with a garbage collector based on reference counting, that's fully integrated with the reference counting model in OpenStep Foundation.

While reference counting is a simple and good technique for small to medium programs, it's usually hard to write programs using it because, as every human activity, is error-prone. The programmer can easily forget to retain or release an object, thus leading to memory leaks. A true garbage collector would solve the problem and would release the programmer from manually keeping track of the allocated memory. libFoundation comes with support for Boehm's garbage collector, a conservative collector available from http://reality.sgi.com/employees/boehm_mti/gc.html.

There is only one source tree for the both versions of the library, the normal OpenStep compatibility library and the support for the Boehm's garbage collector library. To build the last type of library you just have to type:

  $ make gc=yes

This will build and install the library in a separate directory in the GNUstep system tree. For all the GNUstep package that you want to run in a garbage collected environment you will have to add `gc=yes' as an additional argument to make.

The next chapter present the garbage collector based on reference counting. The classes and protocols presented here are only useful when the garbage collector based on reference counting is used.


Go to the first, previous, next, last section, table of contents.