Reputation: 11
I am working on a Swing application and recently, I started to see the following problem:
I have to display in a separate window a very large job report. I close this window, then I re-open the same job report and I get an OutOfMemory Java heap space error.
The JVM is started with -Xmx512m and all the objects that are created when I open the job report take about 300MB on heap. Assuming that there isn't a memory leak, I would expect that the second time I open the same job report the JVM won't throw the OOM. But, looking at the GC logs after closing the first window, I don't see any GC activity.
The strange thing is that after I close the first window, if I take a heap dump with jmap (without the "live" option) the objects can still be seen in the heap dump.
If I run jmap with the dump:live option, the followings happen:
I tested this on Java 6 (1.6.0_25 ad 1.6.0_45, on Windows) and it reproduces all the time.
Running jmap -heap prints :
"using thread-local object allocation.
Mark Sweep Compact GC
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 536870912 (512.0MB)
NewSize = 1048576 (1.0MB)
MaxNewSize = 4294901760 (4095.9375MB)
OldSize = 4194304 (4.0MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 12582912 (12.0MB)
MaxPermSize = 134217728 (128.0MB)
"
JVM is started with the following options:
" -Xms128m
-Xmx512m
-XX:MaxPermSize=128M
-verbose:gc
-XX:+PrintGCTimeStamps
-XX:+PrintGCDetails
-Xloggc:c:\my_gc.log
-XX:+HeapDumpOnOutOfMemoryError"
So, my question is: why are all the objects collected when I take the heap dump with the live option (a sign that there isn't a memory leak) but, if I don't do this, I am unable to re-open another(or the same) job report because I get an OOM error?
Also, I tested another scenario:
Thanks in advance.
Upvotes: 1
Views: 540
Reputation: 11875
So, my question is: why are all the objects collected when I take the heap dump with the live option
The jmap
live option forces a collection. It has been discussed here .
Your observations corroborate that.
What can be done as an exercise is re-opening the window post some GC activity to see whether the memory has been reclaimed.
Upvotes: 1