Java GC Overview
Java GC Overview
Object Types
🧠 Java Memory Overview
🔄 Stack vs Heap
• Stack:
• Heap:
📍 Reference Object
1
⚡ Anonymous Object
new Person().sayHello();
📝 Summary
🧪 Real-Time Example
System.gc(); // Suggest GC
}
}
✅ This will likely print "Object finalized" (not guaranteed) showing when the object is collected.
2
⚙️ Working Principle of Java GC
📂 1. Mark Phase
• Identifies all live (reachable) objects starting from GC Roots (e.g., static fields, active thread stacks).
♻️ 4. Generational GC
⚡ By GC Type
📊 Typical Ranges
3
🎯 Factors Influencing GC Time
• ⚙️ Choice of GC algorithm
• 📏 Size of the heap
• 🧪 Rate of object allocation
• ⏳ Lifespan of objects
• 🎯 Configured pause time goals (tunable via JVM flags)
📝 Enable GC Logs:
🛠️ Recommended Tools:
• 🔍 VisualVM
• 📊 Java Mission Control (JFR)
• 📈 JConsole
• 🧾 GCViewer
📋 Example GC Log:
📚 Summary Table