[Gc] leak with finalizers

Boehm, Hans hans.boehm at hp.com
Wed Dec 22 12:07:46 PST 2004


Paolo -

Did you see a growing leak?

If so, I can't reproduce the problem.  I saw the process stabilize at
anywhere between 17 and 58MB.  This was under Linux, on IA64 and X86.

17 Megabytes looks reasonable to me.
I did not yet investigate why it takes 58MB in some cases.  That does seem
high.  On the other hand, this benchmark is such that a few old pointers
left around on the stack could drastically affect memory use.  And I
got the higher numbers after enabling threads, which might cause certain
stack locations not to be overwritten regularly.  And the finalization
count reflects the fact that a few lists are still being considered
live.

If you were seeing this on Windows, could you retry with 6.4, and see
if it's fixed there?

(Even on Linux, that might be interesting, since the GC_words_wasted
calculation was wrong in 6.3, and that could make s difference, though
I didn't actually see much of that.)

Hans

> -----Original Message-----
> From: gc-bounces at napali.hpl.hp.com
> [mailto:gc-bounces at napali.hpl.hp.com]On Behalf Of Paolo Molaro
> Sent: Wednesday, December 22, 2004 9:03 AM
> To: Gc at napali.hpl.hp.com
> Subject: [Gc] leak with finalizers
> 
> 
> Hi.
> I distilled a C version from a bug report of a mono user.
> The GC seems to leak memory when using finalizers in
> some specific way (libgc version 6.3).
> The test case follows:
> 
> #include <gc/gc.h>
> 
> static int fin_counter = 0;
> static int alloc_counter = 0;
> 
> static void
> finalizer (void *o, void *d) {
> 	fin_counter++;
> 	/* do nothing */
> }
> 
> typedef struct {
> 	void *array;
> 	void *next;
> } Final;
> 
> int main (int argc, char* argv[]) {
> 	Final *list = NULL;
> 	int count = 0;
> 	while (1) {
> 		Final *obj = GC_malloc (sizeof (Final));
> 		/* random sizes cause the GC to leak */
> 		obj->array = GC_malloc (5000 + ((int)obj & 0xfff));
> 		/*obj->array = GC_malloc (5000);*/
> 		obj->next = list;
> 		GC_REGISTER_FINALIZER_NO_ORDER (obj, finalizer, 
> NULL, NULL, NULL);
> 		/* we don't leak if we don't add to a temporary list */
> 		//list = obj;
> 		list = obj;
> 		++count;
> 		++alloc_counter;
> 		if (count == 1000) {
> 			list = NULL;
> 			count = 0;
> 			printf ("fin counter: %d, alloc 
> counter: %d\n", fin_counter, alloc_counter);
> 		}
> 	}
> }
> 
> Note that, if a constant size is used in the array GC_malloc(),
> there is no leak. There is also no leak if we don't temporary
> keep alive the objects in a list.
> Setting GC_DUMP_REGULARLY always reports:
> 0 objects are eligible for immediate finalization
> but the finalizer gets executed (at least in this test case).
> Thanks.
> 
> lupus
> 
> -- 
> -----------------------------------------------------------------
> lupus at debian.org                                     debian/rules
> lupus at ximian.com                             Monkeys do it better
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
> 


More information about the Gc mailing list