Aoop
Table of Contents
1. Garbage collection
Collecting objects (garbage) which are no longer being used to improve the runtime of the program.
1.1. Garbage collection works in sweeps
Eachs sweep removes garbage. This works sismilarly to the machine cycle.
1.1.1. Mark
Mark objects to be deleted
1.1.2. Delete
Delete this objects
1.1.3. Compaction
Arrange objects into relevant generations
1.2. Generational garbage collection
We can define objects wih different generation
1.2.1. Eden
Objects that were just created
1.2.2. Survivor
Young objects that just survived a sweep
1.2.3. Old
Objects which have survive many GC sweeps
1.3. Type of garbage collectors
1.3.1. Serial
- Runs on a single core.
- App pauses for minor and major garbage collection.
1.3.2. Parallel
- Runs on multiple cores.
- App pauses fo both minor and major garbage collection.
- Generally better, but only good when you have the resources for this.
1.4. Main GC algorithms
1.4.1. Concurrent Matk and Swrrp (CMS) (Deprecated on JDK9)
- App only pauses on special cases
- Uses more CPU for concurrent collectors
- No compaction
1.4.2. G1 (Garbage 1st) Garbage Collector
- Simiar to CMS but does compaction (What is compaction?)
- Collection on the long term is more predictable than CMS
- Needs more memory to manage regions
- It might save memory tho due to compaction
1.4.3. Z Garbage Collector (Not exam material)
- Concurrent
- Region based
This garbage collector is scalable. It can have a heap size of 8MB to 16TB). It also does not pause.