[Mono-list] How to use the Boehm garbage collector

Jonathan Pryor jonpryor@vt.edu
Mon, 03 May 2004 07:05:27 -0400


On Mon, 2004-05-03 at 05:30, HannibAl Bundie wrote:
<snip/>
> After the installation of gc6.2 I don't know what I have to do. I have read 
> that I must rebuilt the mono core environment, but I have installed mono 
> with RPM packages. So, is there any other way to use Boehm collector ?

What are you trying to do, exactly?  Mono already uses Boehm GC 6.2,
which is included with the mono source tree (along with some
Mono-specific patches).

If you want to use a different Boehm GC, you have to rebuild Mono from
source.  Period.  When configuring Mono, give it the --with-gc=boehm
argument to use an already installed Boehm GC.  The default is
--with-gc=included, which uses the Mono-provided Boehm GC.

> Also, I would be very grateful if I could have an example of the use of 
> Boehm collector with a C# program.

C# runs in a garbage collecting environment.  To use the Boehm
collector, or any collector for that matter, you...do nothing.  That, of
course, is the whole point to GC systems -- the programmer doesn't need
to do anything.  Just keep allocating memory, and the GC will
automatically collect it when memory runs low.

There are some caveats.  You need to make sure that the memory can be
collected, that your memory is actually garbage at some point.  You can
speed up the process by nulling out fields and variables when you no
longer use them.  Long-living GC objects can slow things down,
especially if they're *large*, long-living objects...

MSDN has a variety of articles describing what programs can do to make
the GC more efficient.

 - Jon