How is memory managed in python?
Memory management is very important for any code writer. As writing an efficient code means a code which takes less memory and performs well.
It is process of efficiently allocating and de-allocating memory.
Python memory is managed by Python private heap space. All Python objects and data structures are located in a private heap. This private heap is managed by the Python memory manager.
The allocation of Python heap space for Python objects is done by the Python memory manager.
We also have a garbage collector in python. It helps to free memory block which is not in use. It runs during a program execution and gets active if the reference count reduces to zero.
We can easily import garbage collector in python.
import gc
Garbage collector has many functions which can be used to free up memory blocks.
In this way we can manage memory in python.