[Gc] running GC only on demand

Alec Orr Alec.Orr at wbemsolutions.com
Wed Feb 23 07:27:40 PST 2005


There are 3 functions in gc.h which you could use.  When you start your 
application, call GC_disable(), then make a function like so:

void MyExplicitGC(void) {

	/* (Re) Enable garbage collection  */
	GC_enable();

	/* invoke a full world stopped collection */
	GC_gcollect();

	/* Disable the GC, even GC_gcollect calls are in effective*/
	GC_disable();
}

To make sure GC's are happening when you expect, you can set the 
environment variable GC_PRINT_STATS=1 while your app runs.  The GC will 
log collection statistics as they happen.

Bear in mind that GC_enable() and GC_disable() calls are reference 
counted.  Two calls to GC_enable() and two calls to GC_disable() will 
disable garbage collection.  Two calls to GC_enable() and ONE call to 
GC_disable() means that garbage collection is still enabled.

Hope this helps,
Alec



Bojan Šernek wrote:
> If I understand correctly, the GC runs collections in between alloc's 
> (when it sees fit to do so). How can I disable this feature and make 
> sure a GC happens only when I run it?
>  
> Thanks,
> Bojan Sernek.
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4686 bytes
Desc: S/MIME Cryptographic Signature
Url : http://napali.hpl.hp.com/pipermail/gc/attachments/20050223/d3c65233/smime.bin


More information about the Gc mailing list