views:

206

answers:

3

We have recently upgraded one of our applications from Java 1.4 to Java 6.

With some load & performance tests, we observed that available memory stayed in general at much lower levels in Java 6 than at what it used to be with Java 1.4.

After some profiling on the app with Java 6, we noticed that many objects no longer referenced by any other objects (i.e. candidates for garbage collection) stayed in memory and were apparently never garbage collected. We took that as the explanation for the lower available memory.

Question is: did the way garbage collection behaves changed from Java 1.4 to Java 6?

+13  A: 

did the way garbage collection behaves changed from Java 1.4 to Java 6?

Definitely!

Java 1.4 to Java 6 is a pretty long timespan (almost 5 years between the initial releases and more than 8 years between the initial 1.4 release and the current Java 6 release, according to this wiki article).

Many changes and optimizations are applied in that time and you should not really care as long as your program still works.

Having more used memory only means that the JVM doesn't waste time with garbage collection when it doesn't need to. If you want it to use less memory, then you should reduce the maximum heap (or otherwise tweak the JVM parameters; this article explains how to do that in Java 5, much of the advice is still applicable).

It's somewhat different if you actually get OutOfMemoryError that you didn't get previously. Then you should check how you use weak and soft references or as a last resort try to find out if you hit a JVM bug.

Joachim Sauer
+5  A: 

There have been several optimizations on garbagecollecting between 1.4 and 5 and between 5 and 6

oracle/sun has some whitepapers on the performance differences online.

http://java.sun.com/performance/reference/whitepapers/5.0_performance.html#2.11

http://java.sun.com/performance/reference/whitepapers/6_performance.html#2.2

Nikolaus Gradwohl
+2  A: 

Java SE changed a lot in 8 years.

Concerning the garbage collector, it has been improved a lot with Java SE 6. In Java SE 6 Update 14 the new Garbage First GC was introduced.

Colin Hebert
While G1 is shipped with releases >= u14, it is not enabled by default in any Java 6 release, as far as I know.
Joachim Sauer
It isn't, you have to activate it with `-XX:+UnlockExperimentalVMOptions -XX:+UseG1GC`
Colin Hebert
@Colin HEBERT: just be prepared for some segfaults and crashes of the VM, unless you are using G1 with Java 7.
tulskiy