java-user@lucene.apache.org
[Top] [All Lists]

Re: 2.1-dev memory leak?

Subject: Re: 2.1-dev memory leak?
From: Michael McCandless
Date: Fri, 01 Dec 2006 10:01:17 -0500
Otis Gospodnetic wrote:
Hi Mike,

Thanks for looking into this.  I think your stress test may match my production 
environment.
I think System.gc() never guarantees anything will happen, it's just a hint.

I've got the following in one of my classes now.  Maybe you can stick it in 
your stress test and look at that last number at the bottom of this snippet.

    private static final MemoryMXBean bean = 
ManagementFactory.getMemoryMXBean();
...
        LOG.info("Bean: " + bean);
        LOG.info("Heap memory usage: " + bean.getHeapMemoryUsage());
        LOG.info("Non-heap memory usage: " + bean.getNonHeapMemoryUsage());
        LOG.info("Objects pending finalization: " + 
bean.getObjectPendingFinalizationCount());
        long freeMemBefore = Runtime.getRuntime().freeMemory();
        LOG.info("Running garbage collector via bean...");
        bean.gc();
        long freeMemAfter = Runtime.getRuntime().freeMemory();
        LOG.info("Total Memory      : " + Runtime.getRuntime().totalMemory());
        LOG.info("Max Memory        : " + Runtime.getRuntime().maxMemory());
        LOG.info("Free Memory Before: " + freeMemBefore);
        LOG.info("Free Memory After : " + freeMemAfter);
        long memDelta = freeMemAfter-freeMemBefore;
        LOG.info("Free Memory Now   : " + memDelta);
        LOG.info("Heap memory usage: " + bean.getHeapMemoryUsage());
        LOG.info("Non-heap memory usage: " + bean.getNonHeapMemoryUsage());
        LOG.info("Objects pending finalization: " + 
bean.getObjectPendingFinalizationCount());


Neat -- this is a nice interface!  OK, yes indeed after calling
System.gc() the "object pending finalization count" is often
non-zero (and often very high).  Apparently System.gc() is very
much "a suggestion".

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@xxxxxxxxxxxxxxxxx
For additional commands, e-mail: java-user-help@xxxxxxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>