The Art of C++

The entire garbage collector is shown here. As explained, the garbage collector works by creating a new pointer type 
that provides built-in support for garbage collection based on reference counting. The garbage collector is 
single-threaded, which means that it is quite portable and does not rely upon (or make assumptions about) the 
execution environment. This code should be stored in a file called gc.h.
There are two things to notice as you look through the code. First, most of the member functions are quite short and 
are defined inside their respective classes in the interest of efficiency. Recall that a function defined within its class is 
automatically in-lined, which eliminates the overhead of a function call. Only a few functions are long enough to require 
their definition to be outside their class.
Secondly, notice the comment near the top of the file. If you want to watch the action of the garbage collector, simply 
turn on the display option by defining the macro called DISPLAY. For normal use, leave DISPLAY undefined.