Finding memory leaks
Thomas Aeby
aeby@graeff.com
Mon Feb 23 21:35:00 GMT 2004
Hello,
I'm trying to find memory leaks in one of my Java programs. So far I
have tried adding a small native C routine just using GC_* calls in
order to dump out a list of objects in use and added a little Perl
program taking this list, finding the associated classes' names and
printing some statistics. Rather than the expected "oh, I get increasing
numbers of class X instances" I see huge numbers of objects I cannot
find any reason why they shouldn't be collected by the garbage
collector (like e.g. FileInputStream/FileDescriptor objects, byte[] and
char[] arrays, Date stuff, etc. which are mostly allocated/valid in a
local block only).
Now I'm somewhat stuck. My questions:
- I tried to build GC with --enable-full-debug in order to get
backtraces telling me why objects aren't collected. Unfortunately,
gcj does not build with this enabled - has anyone succeeded and
can tell me how?
- Are there any known issues with the garbage collector? It seems
that under some circumstances the collector is basically very
unwilling to quickly collect objects. Is this due to the
incremental mark/sweep algorithm?
- Is there some way of really really force a complete mark/sweep
run? I'm not sure if GC_gcollect (aka System.gc()) does really
do the complete thing ... is it?
I'm still pretty sure it's me who is doing something bad rather than
GCJ not working as it should :-). But without GC debugging it's nearly
impossible to find out why objects aren't collected. How do you debug
such problems?
So far I haven't been able to reproduce the problems I see in a
program sufficiently small to serve as an example. I've already
seen that GC tends to leave behind stray objects from time to
time, e.g. a thread like
Thread x = new Thread() {
char [] buffer = new char[16384];
public void run() {
// do something with buffer
}
...
will leave behind 32k chunks from time to time (not always) while
Thread x = new Thread() {
public void run() {
char [] buffer = new char[16384];
// do something with buffer
}
won't (at least not in my test cases).
Any hint appreciated!
Best regards,
Tom
---------------------------------------------------------------------------
Thomas Aeby, Kirchweg 40, 1735 Giffers, Switzerland, Voice : (+41)26
4180040
Internet: aeby@graeff.com PGP public key
available
----------------------------------------------------------------------------
P: Ich kann doch (theoretisch) auch Menschen gefangen halten und
trotzdem
wissen ob die dann freiwillig mit mir Sex haben oder nicht?
M: Das nennt sich dann Heirat und Ehe! -- Martin Freiberg in d.t.l.
--
----------------------------------------------------------------------------
Thomas Aeby, Kirchweg 40, 1735 Giffers, Switzerland, Voice : (+41)26
4180040
Internet: aeby@graeff.com PGP public key
available
----------------------------------------------------------------------------
A professor is one who talks in someone else's sleep.
More information about the Java
mailing list