Garbage Collection Flashcards
What are the three areas of the Runtime Data Area?
Method Area, Heap Area and Thread(s)(1..n)
Where does JVM collect garbage from?
Usually the Heap Area, but it can also collect form the Method Area, when it is implementation-specific. (new objects are created here)
What does JVM stand for?
Java Virtual Machine
What does the JDK(Java Development Kit) contain?
The Java Class Libraries, the Java compiler and the JVM(Java Virtual Machine).
What does the Java Virtual Machine contain?
Class Loader, the Runtime Data Area, the Execution Engine, the Native Method Interface and the Native Method Library.
Where can the Garbage Collector be found?
In the Execution Engine.
Perks of Garbage Collection.
- memory management
- dangling reference bugs
- space leaks
How does Garbage Collection work in Java?
It recognizes when the allocated objects are no longer needed and deallocates (frees) the memory used by such objects.
Should Garbage Collection be done manually?
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.
What does Object Reachability refer to?
Object A is reached by object B if:
- B contains a variable pointing to A
- B can reach A in any number of steps
What is GC based on?
It is based on reachability from “root objects”
How does Mark-and-Sweep work?
Pause the program while collecting the garbage. It transeverses the whole memory at least twice.
On what generation does GC focus on?
The young generation of created objects.
How does the Mark-and-Sweep method work in the Heap Area?
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).
What are some examples of GC?
- Serial GC
- Parallel GC
- Concurrent Mark and Sweep Collector
- Z Garbage Collector
- Garbage 1st Collector