Figuring Out Why My Program Eats So Much Memory

D

Dale

I need some kind of heap analyzer tool or something that will tell me
what Objects are not getting collected by the GC. The program starts
a bunch of objects, and each object runs in it's own thread. The test
objects usually makes a connection of some type, and does a test. At
the end of the test, or at a timeout, each one of those objects calls
back with the result of the test. These tests are scheduled every 20
minutes. In each of these test objects, the run method stops after it
reports back, and that should be it. But in Windows NT processes, I
see this program takes up more and more memory as the days go by (it's
up to 74,732K at the moment). If I stop and restart, it settles at
about 18,000K, but slowly makes it's way up to that 75,000K range
after a couple of days.

Is there a way to list the objects the JVM thinks are still active?

--Dale--
 
S

Steve W. Jackson

:I need some kind of heap analyzer tool or something that will tell me
:what Objects are not getting collected by the GC. The program starts
:a bunch of objects, and each object runs in it's own thread. The test
:eek:bjects usually makes a connection of some type, and does a test. At
:the end of the test, or at a timeout, each one of those objects calls
:back with the result of the test. These tests are scheduled every 20
:minutes. In each of these test objects, the run method stops after it
:reports back, and that should be it. But in Windows NT processes, I
:see this program takes up more and more memory as the days go by (it's
:up to 74,732K at the moment). If I stop and restart, it settles at
:about 18,000K, but slowly makes it's way up to that 75,000K range
:after a couple of days.
:
:Is there a way to list the objects the JVM thinks are still active?
:
:--Dale--

There are some commercial profiling tools available. We've been using
OptimizeIt, now available from Borland. They may still offer a demo to
get a feel for what it can do.

Another key thing is to get familiar with Java's memory management
scheme in general. It pays to learn how the heap works, about garbage
collection, etc. You do realize that those Thread objects don't go away
when they stop, right? Any Thread (or subclass) is not considered alive
when its run() method terminates, but the object is there until you
remove it -- provided it's referred to anywhere. And, despite what some
people think, it can prevent itself from getting cleaned up if some of
its own member variables reference certain objects outside itself. It's
a complicated topic, when you're forced to get into it.

= Steve =
 
R

Robert Olofsson

Dale ([email protected]) wrote:
: Is there a way to list the objects the JVM thinks are still active?

Get a profiler and check the heap.

In the standard jdk you have the hprof profiler that is not very user
friendly, but always available.

There are a few free profilers like jmp (which I develop and use) find
it at http://www.khelekore.org/jmp/
You can also try mjp at http://mjp.sf.net/ or if you happen to use
eclipse there is the eclipse profiler plugin (havent tried it myself
but seems to provide standard profiling options). Find it at:
http://eclipsecolorer.sourceforge.net/index_profiler.html

If you instead prefer to spen a lot of money you can try jprobe,
optimizeIt or jprofiler (a quick google will show you the
sites). Personally I dont like any of the commercial versions, but
you should be able to find a 30 day trial version if you look
around...

have fun
/robo
 
D

Dale

Steve, Robert & Roedy,

Thanks for the suggestions - things worked out really well. After
checking out the references and web contentes, I settled on
http://www.khelekore.org/jmp/ and picked-up the code there. It was
immediately apparent that a certain test (Object) was not being
garbage collected (there was a zero in the GC column... not what I
expected). So I did a bit of reading (these are objects that are part
of an enterprise integration architecture tool) and found some destroy
methods. Once I put those in there, I was golden (10K and holding for
a few days now). Thanks.

--Dale--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top