Java Garbage Collection Flashcards

1
Q

Types of GC

A

Single(Serial) Collector
Parallel Collector
Concurrent Mark and Sweep Collector
Garbage First Garbage Collector ( G1GC)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Serial Collector

A

Uses single thread to collect the unused objects. This can be useful small memory footprint applications.

java -XX :+UseSerialGC

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Parallel Collector

A

Uses multiple threads to collect.
Might pause application threads also.
Stop the world approach could freeze the application.

java -XX:UseParallelGC
-XX:ParallelGCThreads - number of parallel GC threads

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

CMS - Concurrent Mark and Sweep

A

Uses multiple GC threads to collect.
It does not force stop the world, but still affects the application threads.

java -XX:+UseParNewGC

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

G1 GC

A

Heap memory is split into multiple regions , and region with lesser free space is selected to clean up the objects.
First it marks the region with unused objects, then sweep phase will kick in for less free space regions.
It is more efficient than CMS.

Java -XX:useG1GC

Java 8 also uses XX:+UseStringDeduplication to deduplicate same string objects to save space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Generations

A

Young -> Tenured -> Permanent

Young generation is split into 1 Eden space and 2 survivor spaces. Initially all objects are allocated into eden space.
Minor collection happens to remove dead objects and move live objects to survivor spaces and eventually to Tenured generation.

Permanent -> is for classes, static methods and other language memory footprint.

https://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Java Reference Types

A

Weak
Soft
Phantom
Finalization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly