1. What are the six reachability states in Java?
Strongly reachable objects
Softly reachable objects
Weakly reachable objects
(Weak Refer: a reference that doesn't protect the referenced object from collection)
Resurrect-able reachable objects
Phantomly reachable objects
Unreachable reachable objects
https://stackoverflow.com/questions/299659/what-is-the-difference-between-a-soft-reference-and-a-weak-reference-in-java
2. How does GC work and when do JVM perform GC


What is Eden: newly created objects will be putted here
What is survivor: objects which survived Eden GC
Why there are two survivors: Only put things to old generation if objects survives many GC
What are the major GCs:
Minor GC: Clean eden, move Eden to survivors
Full GC: Clean entire heap space
When to collet:
Minor When don't have enough space to allocate new space in Eden
Major: New candidate for Old generation is bigger than free space in Old generation
What to collect:
Go through GC roots. Any unreachable objects will be marked as OK to collect
What happened:
stop some threads and finalize some objects
Memory Model
We have stack and heap memories.
Stack:
What's inside:
method (call stack) and local primitive variables. Each thread has stack space here
What gonna happen if stack is full:
StackoverFlow Error
Life Cycle:
Heap:
What's inside:
all reference objects(literally all)
What gonna happen if stack is full:
OutOfMemoryError Error
Size of Stack >> Size of Heap
No comments:
Post a Comment