[Mono-dev] Garbage collection for threads

Debajyoti Bera dbera.web at gmail.com
Fri Jan 11 19:23:29 EST 2008

> > 1)	If an application is blocked on a IO read, will the GC thread still
> > run and collect freed objects ? I thought the GC thread always runs, no
> > matter what, but it does not look like it. What is the intended behaviour
> > ? I hope the answer works for threads too i.e. if some thread is blocked,
> > will the GC clean away objects freed previously in that thread ?
> Yes, it will.

I was of the impression that mono has a separate GC thread 
which 'periodically' and on allocation pressure, goes into a collection mode. 
I was pointed out in the #monodev IRC that any thread could be the GC thread 
(which kind of implied that if some thread is blocked right after it does a 
huge allocation, those objects wont be freed) and secondly, there is no time 
based collection, but collection happens only with allocation.

If there is no time based collection, that means once extra allocations were 
made for whatever reason and shot up RSS (loosely using RSS for memory 
usage), they might still be in memory long after they are discarded and the 
RSS will still show high. This could ok for proper server apps but not for 
desktop apps where users dont mind once in a while memory usage but after the 
operation is done, they expect the memory to come down.

> > 2) After a thread is finished and there are no references of it anywhere,
> > what is an approximate time after which the thread (and the objects
> > created in the Thread.Start method) will be freed ? 1sec/1min/10 min -
> > really I am asking if there is any way the thread could still linger in
> > the memory for a long time (long ~ 10mins or more).
> The thread object might go away, but the OS thread will continue to
> exist.   The OS thread needs to terminate for it to be finished.

Can you elaborate a little more on that ? Just letting a thread run and die on 
its own is not enough:
  Thread thread = new Thread (new ThreadStart (Run))
  thread.Start ();
where Run() does a bunch of allocations. Do you mean I have to 
manually 'terminate' the thread after it stops running ?

- dBera

Debajyoti Bera @ http://dtecht.blogspot.com
beagle / KDE fan
Mandriva / Inspiron-1100 user

More information about the Mono-devel-list mailing list