Python uses two strategies for memory allocation-
(i) Reference counting
(ii) Automatic garbage collection
Reference Counting: works by counting the number of times an object is referenced by others in the system. When an object’s reference count reaches zero, Python collects it automatically.
Automatic Garbage Collection: Python schedules garbage collection based upon a threshold of object allocations and object deallocations. When the number of allocations minus the number of deallocations is greater than the threshold number, the garbage collector is run and the unused blocks of memory are reclaimed.