15.8.2001 Strange phenomenas with Memory and Java#
In our current project we have a memory consuming Calculator-Monster, which eats up to 40 M per instance. That, of course, is not strange phenomena with Java :), but following is: when the object is set to null (we believe everything else related is null also), nothing significant happens with memory. Even more strange is that when we perform System.gc() after nullifying, the use of memory RISES (about 7M). Eventually after few load-close -operations java runs OutOfMemory. Any ideas, questions, experiences? Anything at all is appreciated.--tuomasp
It is my understanding that an object can be both dead (= no longer has references) and still be referenced. Typically you add an object to a Collection of some sort and then forget about it. Or, you may have a reference to the object in Swing (by addXXXListener()).
I had once a problem with a starved thread holding references to an object that was supposedly being garbage collected.
There is an excellent article in Doctor Dobb's Journal that might be of some help.
- http://www.ddj.com/articles/2000/0002/0002l/0002l.htm
- An article describing how to use different reference types to help with memory leaks
Yup, we found the bug, indeed it related to listeners. I strongly recommend above articles to everyone.
--tuomasp
Image 2D API has its own cache mechanism, which sometimes allocates quite huge amounts of memory. It is usually a good idea to turn off the cache in case you have processes that are refresing their once loaded images. The cache would keep all old versions in its internal data structures by default :(
--Asser
The DDJ article has now disappeared for non-subscribers.
We've got a quad processor machine and this made a difference...
To stop OutOfMemory errors, we used these options:
java -Xms128m -Xmx2048m -XX:+UseParallelGC=2 -XX:MaxPermSize=128m
Read up on those switches:
http://www.wilsonmar.com/1javagc.htm#PermMemz
http://www.javaperformancetuning.com/news/qotm026.shtml
--DonRota
The Table of Contents plugin can cause this problem if a header symbol (!) is placed before it because it causes a recursive loop.
--richard, 14-May-2006