garbage collection

Alexandre Oliva oliva at dcc.unicamp.br
Wed May 20 03:25:12 PDT 1998


Davor Cubranic <cubranic at cs.ubc.ca> writes:

> how the objects get freed when they are no longer needed. Admittedly, my 
> program was fairly simple, but I was unable to get any of objects that were 
> temporarily created to be freed.

call System.gc() explicitly, or remove the bounds from your loop.  The
heap grows in large chunks and, before allocating a new chunk, the
garbage collector takes control and tries to free as much memory as
possible, so as to avoid growing the heap.

Since the GC runs as a low priority thread, and context switching is
not preemptive, don't expect it to run unless you leave some free CPU
for it to run.  Inserting `Thread.sleep(10);' in the loop may help
too.  I don't think `Thread.yield();' would help, because GC gets
lower priority.

-- 
Alexandre Oliva
mailto:oliva at dcc.unicamp.br mailto:aoliva at acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil



More information about the kaffe mailing list