[Gc] Collecting large memory blocks

Christian Gudrian christian at gudrian.org
Thu Dec 3 01:58:51 PST 2009


Hello!

Given this simple C++ console application:

// --- 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ---
#include <iostream>

#include <gc_cpp.h>

using namespace std;

static int counter = 0;

void GC_CALLBACK Cleanup(void * obj, void * data)
{
    counter--;
}

void alloc()
{
    for (int i = 0; i < 100; i++)
    {
       counter++;
       new (GC, Cleanup) double[1000000];
    }
}

int main(int argc, char* argv[])
{
    alloc();

    cout << GC_get_heap_size() << "\t"
	<< GC_get_free_bytes() << "\t"
	<< counter << endl;

    GC_gcollect();

    cout << GC_get_heap_size() << "\t"
	<< GC_get_free_bytes() << "\t"
	<< counter << endl;

    return 0;
}
// --- >8 ------ >8 ------ >8 ------ >8 ------ >8 ------ >8 ---

The output on my system is something like:
1154457600      434118656       81
1151590400      503287808       75

A large amount of memory obviously does not get collected.

If I reduce the number of doubles allocated from 1,000,000 to 100,000 the  
output looks like this:
28655616        7774208         18
28655616        14196736        14

Is this behaviour reproducible and/or intended?

The collector (version 7.2.4) is configured like this:

ALL_INTERIOR_POINTERS
JAVA_FINALIZATION
GC_GCJ_SUPPORT
NO_DEBUGGING
USE_MUNMAP
GC_THREADS
THREAD_LOCAL_ALLOC
PARALLEL_MARK

Compiler: Borland C++ 5.6.4 for Win32 (C++Builder 6)

Christian


More information about the Gc mailing list