[Mono-list] How do I force a garbage collection / free a heap

Michael Hutchinson m.j.hutchinson at gmail.com
Sun Nov 15 23:11:47 EST 2009

On Sun, Nov 15, 2009 at 7:04 PM, Mike Christensen <mike at kitchenpc.com> wrote:
> Hi all -
> I have a program that generates some results, but in order to do so it
> must load a whole lotta stuff into memory for calculations.  When this
> is done, I only need the results and not the data in memory.  This
> data might be several hundred megs on the heap or more.
> When I'm done, I want to "free" this data and not have it sit around
> and slow down stuff.  Is there a way to force a GC cycle or just say
> "delete these objects"?  Is there a better design for this sort of
> thing (like can I create my own heap and just release the whole thing
> at once?)  Also, I'm aware that GC will freeze all threads while it
> works, which is okay since I only do this when the application starts
> and I don't mind if the start-up costs are slow (since it's a web
> site)..
> Any pointers would be great!

You can use GC.Collect () to force a collection. Generally it's
advised not to call GC.Collect, because it's best to let the garbage
collector handle its scheduling, but it sounds like your use case is

Michael Hutchinson

More information about the Mono-list mailing list