Garbage Collection Flashcards

1
Q

What are the three areas of the Runtime Data Area?

A

Method Area, Heap Area and Thread(s)(1..n)

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

Where does JVM collect garbage from?

A

Usually the Heap Area, but it can also collect form the Method Area, when it is implementation-specific. (new objects are created here)

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

What does JVM stand for?

A

Java Virtual Machine

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

What does the JDK(Java Development Kit) contain?

A

The Java Class Libraries, the Java compiler and the JVM(Java Virtual Machine).

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

What does the Java Virtual Machine contain?

A

Class Loader, the Runtime Data Area, the Execution Engine, the Native Method Interface and the Native Method Library.

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

Where can the Garbage Collector be found?

A

In the Execution Engine.

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

Perks of Garbage Collection.

A
  • memory management
  • dangling reference bugs
  • space leaks
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does Garbage Collection work in Java?

A

It recognizes when the allocated objects are no longer needed and deallocates (frees) the memory used by such objects.

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

Should Garbage Collection be done manually?

A

JVM does not support manual deallocation, but you can call the GC explicitly | System.gc();
It does not enforce garbage collection either:
JVM implementations provide GC.

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

What does Object Reachability refer to?

A

Object A is reached by object B if:
- B contains a variable pointing to A
- B can reach A in any number of steps

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

What is GC based on?

A

It is based on reachability from “root objects”

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

How does Mark-and-Sweep work?

A

Pause the program while collecting the garbage. It transeverses the whole memory at least twice.

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

On what generation does GC focus on?

A

The young generation of created objects.

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

How does the Mark-and-Sweep method work in the Heap Area?

A

We have young objects where GC runs often(minor collection), devided into two: the ones that just survived a sweep and the ones that were just created and never sweeped. The we have the old objects where GC seldom runs(major collection).

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

What are some examples of GC?

A
  • Serial GC
  • Parallel GC
  • Concurrent Mark and Sweep Collector
  • Z Garbage Collector
  • Garbage 1st Collector
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Serial Garbage Collector(+-)

A

+ works at any situation
- runs on a single core
- application pauses for both minor and major collection

17
Q

Parallel Garbage Collection(+-)

A

+ run on multiple cores
- application pauses for both minor and major collection

18
Q

Concurrent Mark-and-Sweep (CMS)

A

+ application only pauses on special cases
- uses more CPU for concurrent collectors
- no compaction

19
Q

G1 Collector

A

+ similar to CMS but does compaction
+ collection behaviour on the long term is more predictable than CMS
- requires more memory
+ but may save more due to compaction