GC leaks debugging

Erik Groeneveld erik@cq2.nl
Fri Apr 8 08:12:00 GMT 2011


> Perhaps the program allocates many different (possibly large) sizes,
> which remain on the free list, but cannot be used because the next
> objects requested are slightly bigger.  I have to study this somewhat
> more.

This program has similar behavior, but without Lucene.  Although it
never allocates a block bigger than 10 MB, the heap keeps growing. It
was 70 MB before the program terminated (normally).

#include <stdio.h>
#include <cstdlib>
#include <math.h>

extern "C" void* _Jv_AllocBytes(int);
extern void _Jv_InitGC(void);
extern long _Jv_GCTotalMemory (void);
extern long _Jv_GCFreeMemory(void);

int main(int argc, char *argv[]) {
    _Jv_InitGC();
    for(int n=4096; n<10000000; n++) {
        int size = (rand() % n/4096 +1) * 4096; // allocate many different sizes
        void* p = _Jv_AllocBytes(size);
        if(n % 1000 == 0) {
            printf("%d %d %d %d\n", n, size, _Jv_GCTotalMemory(),
_Jv_GCFreeMemory());
            fflush(stdout);
        }
    }
}

When making a graph of the printed data, it's shape look familiar to
what I see with Lucene.  While the heap is mostly empty, the collector
keeps growing it.
The question is, will it grow forever, or is there an upper bound?
What will it do when the free lists become really large?

Erik



More information about the Java mailing list