...
Wiki Markup |
---|
Since JDK 1.2, the new generational garbage collector has reduced memory allocation related costs to minimal levels, even lesser than C/C++. Deallocation has also become cheaper such that the cost of garbage collection is commensurate with the number of _live_ objects in the _younger generation_ and not the _total_ number of objects allocated since the last run. Memory is managed in generations to optimize the collection. The younger generation consists of short-lived objects. A minor collection on the younger generation is performed when it fills up with dead objects. \[[Oracle 10a2010a|AA. Java References#Oracle 10a]\] |
Wiki Markup |
---|
Note that objects in the _younger generation_ that persist for longer durations are _tenured_ and are moved to the _tenured generation_. Very few _younger generation_ objects continue to live through to the next garbage collection cycle; the rest become ready to be collected in the impending collection cycle. \[[Oracle 10a2010a|AA. Java References#Oracle 10a]\] |
...
Wiki Markup |
---|
This noncompliant code example (based on \[[Goetz 042004|AA. Java References#Goetz 04]\]) shows a container, {{MutableHolder}}. In {{MutableHolder}}, the instance field {{value}} can be updated to reference a new value using the {{setValue()}} method which makes its existence long-term. This slows down garbage collection. |
...
Wiki Markup |
---|
This compliant solution improves by narrowing down the scope of the variable {{buffer}} so that the garbage collector collects the object as soon as it goes out of scope. \[[Bloch 082008|AA. Java References#Bloch 08]\] |
...
References
Wiki Markup |
---|
\[[API 062006|AA. Java References#API 06]\] Class {{System}} \[[Commes 072007|AA. Java References#Commes 07]\] Garbage Collection Concepts and Programming Tips \[[Goetz 042004|AA. Java References#Goetz 04]\] \[[Lo 052005|AA. Java References#Lo 05]\] \[[Bloch 082008|AA. Java References#Bloch 08]\] Item 6: "Eliminate obsolete object references" \[[MITRE 092009|AA. Java References#MITRE 09]\] [CWE ID 405|http://cwe.mitre.org/data/definitions/405.html] "Asymmetric Resource Consumption (Amplification)" |
...