- Garbage collection are mainly used in the Python programming
and it also helps in the memory management.
- It is an automatic memory management in which it will free the
memory after the usage of the RAM from the CPU .
Working of Garbage collection:
- The garbage collector used to keep a list of all items in his
mind. In the first generation of the garbage collector, a new
object will begin its life. If Python performs a generation garbage
collection operation and the object is surviving , it then passes
into a second, older generation.
- The Python garbage collector will be having a total of three
generations, and an object would be passing into an older
generation if the garbage collection phase of its current
generation persists.
- For each generation, the garbage collection module will have a
threshold number of objects. If the number of items reaches to the
threshold, then the garbage collector would start a collection
process. For any object that survives this phase, it would be
passed through an older generation.
- The program to get the threshold count would be:
- import gc
gc.get_threshold()
TBD stands for To Be decremented ,and its a kind of cross
reference stack used in the python programming . It tells the how
operation would be decremented based on the collection of
memory.
The function would be creating the new cell which will be
referred to top of the stack and then creating the reference by
increasing the reference count and followed by the destroying of
the reference with the help of stack reference.