Learn Before
Concept

Generational Garbage Collection

Sometimes objects have reference counts above 0, but no longer have references to it. These objects should be deallocated, but reference counting alone won't deallocate them. These are called unreachable objects. Garbage collectors will look for these unreachable objects and deallocate them. Generational garbage collection runs under the assumption that most objects have a very short lifespan and can be deallocated shortly after creation. The older an object is, the less likely it is to become unreachable. This assumption is true for many Python programs. So, all objects are organized into three categories, referred to as generations. Garbage collection occurs separately for each generation and at different frequencies. All new objects start at generation 0 and if they survive a garbage collection that surveys generation 0, they are elevated to generation 1, which is surveyed less often. If they survive a garbage collection across generation 1, they move on to generation 2, which is the least surveyed.

0

1

Updated 2021-06-14

Contributors are:

Who are from:

Tags

Python Programming Language

Data Science