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

Petit Eric surfzoid at gmail.com
Tue Nov 17 03:28:02 EST 2009

I would say, be carefull with GC.Collect() :

2009/11/17 Mike Christensen <mike at kitchenpc.com>:
> Thanks!  This is exactly what I needed.  I did some tests and with a
> large database (probably the most data I'll ever have) I allocated
> about 500 megs on the heap.  Once I null out my "temporary workspace",
> GC.Collect() takes about 30ms to run and my process goes back down to
> about 18 megs..  If I don't run GC.Collect(), I see the 500 megs
> sitting around for quite some time..
> Since this is simply a web site start-up routing, I think this is the
> best way to go..
> Mike
> On Sun, Nov 15, 2009 at 8:11 PM, Michael Hutchinson
> <m.j.hutchinson at gmail.com> wrote:
>> 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
>> okay.
>> --
>> Michael Hutchinson
>> http://mjhutchinson.com
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list


 Small Eric Quotations of the days:
 I have no special talents. I am only passionately curious

More information about the Mono-list mailing list