Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is a not so well known corner case with generational garbage collectors. (For a brief description read the answer by <a href="https://stackoverflow.com/questions/306862/does-using-final-for-variables-in-java-improve-garbage-collection#306966">benjismith</a> for a deeper insight read the articles at the end).</p> <p>The idea in generational GCs is that most of the time only young generations need to be considered. The root location is scanned for references, and then the young generation objects are scanned. During this more frequent sweeps no object in the old generation are checked.</p> <p>Now, the problem comes from the fact that an object is not allowed to have references to younger objects. When a long lived (old generation) object gets a reference to a new object, that reference must be explicitly tracked by the garbage collector (see article from IBM on the <a href="http://www.ibm.com/developerworks/java/library/j-jtp11253/" rel="nofollow noreferrer">hotspot JVM collector</a>), actually affecting the GC performance. </p> <p>The reason why an old object cannot refer to a younger one is that, as the old object is not checked in minor collections, if the only reference to the object is kept in the old object, it will not get marked, and would be wrongly deallocated during the sweep stage.</p> <p>Of course, as pointed by many, the final keyword does not reallly affect the garbage collector, but it does guarantee that the reference will never be changed into a younger object if this object survives the minor collections and makes it to the older heap.</p> <p>Articles: </p> <p>IBM on garbage collection: <a href="http://www.ibm.com/developerworks/java/library/j-jtp10283/" rel="nofollow noreferrer">history</a>, in the <a href="http://www.ibm.com/developerworks/java/library/j-jtp11253/" rel="nofollow noreferrer">hotspot JVM</a> and <a href="http://www.ibm.com/developerworks/java/library/j-jtp01274.html" rel="nofollow noreferrer">performance</a>. These may no longer be fully valid, as it dates back in 2003/04, but they give some easy to read insight into GCs.</p> <p>Sun on <a href="http://java.sun.com/docs/hotspot/gc1.4.2/" rel="nofollow noreferrer">Tuning garbage collection</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload