Garbage Collection Algorithm — Mark & Sweep


Memory Leak fixed

Garbage Collection

Mark & Sweep Algorithm

Mark Phase

After Completion of Mark Phase

Sweep phase

After completion of Sweep Phase
// Pseudo Code for Mark 
If root.marked = false then
root.marked = true
For each v root.references()
For each object in heap
If object.marked = true then
object.marked = false

Advantages of Mark & Sweep

Disadvantages of Mark & Sweep

Senior Software Engineer @Microsoft. Writes about Distributed Systems, Programming Languages & Tech Interviews

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store