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?
Garbage collector destroys these objects. The main objective of Garbage Collector is to free heap memory by destroying unreachable objects. The garbage collector is the best example of the Daemon thread as it is always running in the background. How Does Garbage Collection in Java works?
It makes java memory efficient because garbage collector removes the unreferenced objects from heap memory. It is automatically done by the garbage collector(a part of JVM) so we don't need to make extra efforts.
There is a difference in terms of how you activate garbage collection logging for Java 8 and earlier and for the newer Java versions. For Java 8 and earlier you should add the following flags to your JVM-based application startup parameters: Where the PATH_TO_GC_LOG_FILE is the location of the garbage collector log file. For example:
By using logs we can understand what the JVM tells us about the garbage collectors’ work. The garbage collector log is a text file produced by the Java Virtual Machine that describes the work of the garbage collector. It contains all the information you could need to see how the memory cleaning process works.
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.
There have been several optimizations on garbage collecting between 1.4 and 5 and between 5 and 6.
Oracle/Sun have some whitepapers on the performance differences online:
Java 5 Performance White Paper
Java 6 Performance White Paper
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With