Memory Management in Python

Memory Management in Python

Memory Management is handled by Python Memory Manager. When an object is created in program, Python Memory manager allocates memory on heap. Heap is part of the Random Access memory (RAM) in our system. Memory allocation is object specific. Based on the size of the object declared in program, Python Memory Manager takes a call. All these allocations happens inside the system and are not managed by users as we do in C programming using malloc(), calloc(), free(). Everything is handled by interpreter in Python.

Ultimately, everything happens as a part of Operating system. The Memory manager has to interact with the OS memory manager to ensures that sufficient space is allocated for the objects. While we talk only about objects here, the non-object related memory access is also handled by memory manager.

When we declare a variable in Python as below:

a = 25

25 is stored in memory and the variable reference is assigned to a. The reference can be printed using id(a) 


Post a Comment

0 Comments