Please read the following web page created by Andrew Tolmach at Portland State University:
For further reading, look at:
There is an excellent mark and sweep garbage collector that you can use in your C and C++ programs. It is called gc. This web page also contains links to many papers about benefits of garbage collection etc.