Re: [Gc] Collecting large memory blocks

Ivan Maidanski ivmai at mail.ru
Wed Dec 2 07:01:46 PST 2009


Hi!
"Christian Gudrian" <christian at gudrian.org> wrote:
> Hello!
>
> I am using the most recent CVS version of the collector under Win32
> compiled with C++Builder6.
>
> I wrote a simple test program to verify the operation of the collector
> under different conditions.  During the tests I constantly monitor the
> values of GC_get_heap_size() and GC_get_free_bytes() to judge if certain
> memory blocks which became unreachable got collected.  This of course
> involves manually calling GC_gcollect() to force a collection cycle.
>
> I discovered that large memory blocks do not get reclaimed once they
> become unreachable.  For example:
>
> GC_MALLOC(100000)  -> gets collected during the next cycle
>                          (GC_get_free_bytes() increases accordingly)
> GC_MALLOC(1000000) -> never gets collected
>                          (GC_get_free_bytes() does not increase)
>
> Apart from the amount of memory allocated both calls take place under the
> same conditions.
>
> Is this behavior intended, and if so: why?
>
> Christian Gudrian

Well, I tried the following simple test (if you're right it should consume 10 GiB):

/* test1.c */
#include "gc.h"
#include <stdio.h>

int main(void)
{
 int i;
 for (i = 0; i < 10000; i++)
  GC_MALLOC(1000000); /* 1 MiB */
 printf("%ld\n",GC_get_heap_size());
 return 0;
}

The compiler is: Borland C++ 5.82 for Win32 Copyright (c) 1993, 2005 Borland

The build command is:

bcc32 -Ox -a8 -w-par -w-csu -w-ccc -w-rch -w-rvl -WM -4 -DALL_INTERIOR_POINTERS -DJAVA_FINALIZATION -DGC_GCJ_SUPPORT -DNO_DEBUGGING -DUSE_MUNMAP -DGC_THREADS -DTHREAD_LOCAL_ALLOC -DPARALLEL_MARK -I.\include -I.\libatomic_ops\src test1.c extra\gc.c

The test work correctly: it prints something near 1.5 MiB. Does this test runs ok on your side?

Notes:
1. to "judge if certain memory blocks which became unreachable got collected" you could by assigning a finalizer to that object.
2. Borland compilers treat pointers as signed ints (so you shouldn't create programs (with it) which need heap larger than 2 GiB).

Bye.


More information about the Gc mailing list