Object References and Garbage Collection
This chapter provides tutorial notes and example codes on Object References and Garbage Collection. Topics include object reference types; strong reference test program; final reference test program; dead objects with final references in heap; performance impact of final references.
These sections are omitted from this Web preview version. To view the full content,
see information on how to obtain the full version this book.
Object Reference Types
Strong Reference GC Test Program
Strong Reference Test with Serial GC
Final Reference GC Test Program
Final Reference Test with Serial GC
-XX:+PrintReferenceGC - Print Reference Counts
Performance Impact of Final References
- Java uses 6 types of references: strong reference, soft reference, weak reference,
final reference, phantom reference, JNI weak reference.
- Strong references are normal references used Java to retrieve object values.
- Final references are used by the finalizer thread to execute finalize() object methods.
- When all strong references are removed from an object, it becomes a dead object.
- If a dead object has a finalize() method, it is queued with a final reference for the finalizer
thread to process.
- Garbage collectors will leave dead objects with final references in the heap
until they are processed by the finalizer thread.
- Simple tests show final references slowing down application execution by 2 times!
- Do not use finalize() methods in your Java application, if possible.
Table of Contents
About This Book
Heap Memory Area and Size Control
JVM Garbage Collection Logging
Introduction of Garbage Collectors
Serial Collector - "+XX:+UseSerialGC"
Parallel Collector - "+XX:+UseParallelGC"
Concurrent Mark-Sweep (CMS) Collector - "+XX:+UseConcMarkSweepGC"
Garbage First (G1) Collector - "+XX:+UseG1GC"
►Object References and Garbage Collection
Garbage Collection Performance Test Program
Performance Tests on Serial Collector
Performance Tests on Parallel collector
Performance Tests on Concurrent collector
Performance Tests on G1 collector
Garbage Collection Performance Test Summary
Full Version in PDF/EPUB