Onkar Lapate’s Post

How does Generational Garbage Collector (GC) clean up circular references in Python? Python doesn’t scan all objects for circular references all the time. That will be time-taking. It divides objects into 3 different generations - Generation 0 → Every new object starts here, cleaned very frequently Generation 1 → Objects that survived Gen 0, cleaned less often Generation 2 → Long-living objects (configs, globals, caches), cleaned very rarely Objects that survive cleanup get promoted to the next generation. The Generational GC asks a question: "If I ignore references from the outside world, are you only pointing at each other?” If yes → Python breaks the cycle → reference counts drop → memory is freed. There can be tiny “random” latency spikes in Python apps, often the GC waking up especially for Generation 2. Reference Counting and Generational GC together make memory management feasible in Python. I am trying to learn Python Internals in detail and will share my learnings. Do follow along and tell your experiences in comments. #Python #PythonInternals #SoftwareEngineering #BackendDevelopment

  • graphical user interface, text, application, email

To view or add a comment, sign in

Explore content categories