Java Reference
In-Depth Information
GC. Unlike CMS, it is intended to be usable in workloads that have higher through‐
put requirements.
G1 uses a coarse-grained approach to memory, called regions, and focuses its atten‐
tion on regions that are mostly garbage, as they have the best free memory recovery.
It is an evacuating collector, and does incremental compaction when evacuating
individual regions.
The development of a new production-grade collector that is suitable for general-
purpose use is not a quick process. Accordingly, although G1 has been in develop‐
ment for some years, as of early 2014, G1 is still less efficient than CMS on most
benchmarks. Having said that, the gap has been steadily closing and G1 is now
ahead on some workloads. It is entirely plausible that G1 will become the most com‐
mon low-pause collector in the coming months and years.
Finally, HotSpot also has a Serial (and SerialOld collector) and a collector known as
“Incremental CMS." These collectors are all considered deprecated and should not
be used.
There is one old technique for resource management known as inalization that the
developer should be aware of. However, this technique is extremely heavily depre‐
cated and the vast majority of Java developers should not directly use it under any
Finalization has only a very small number of legitimate use
cases, and only a minority of Java developers will encounter
them. If in any doubt, do not use finalization— try -with-
resources is usually the correct alternative.
The finalization mechanism was intended to automatically release resources once
they are no longer needed. Garbage collection automatically frees up the memory
resources used by objects, but objects can hold other kinds of resources, such as
open files and network connections. The garbage collector cannot free these addi‐
tional resources for you, so the finalization mechanism was intended to allow the
developer to perform cleanup tasks as closing files, terminating network connec‐
tions, deleting temporary files, and so on.
The finalization mechanism works as follows: if an object has a finalize() method
(usually called a inalizer ), this is invoked sometime after the object becomes unused
(or unreachable) but before the garbage collector reclaims the space allocated to the
object. The finalizer is used to perform resource cleanup for an object.
In Oracle/OpenJDK the technique used is as follows:
Search WWH ::

Custom Search