Memory Management in Python

Memory allocation is important to any software developer as writing efficient code means writing memory-efficient code. In Python, memory allocation and deallocation are done automatically on runtime. the programmer need not allocate memory while creating objects or deallocate memory when deleting the object. Memory management in Python involves a private heap containing all Python objects and data structures. PVM will take care of such issues.

Everything is considered as an object in python, a string is objects, functions are objects, lists are objects, modules are also objects. memory should be allocated for every object. this object is stored on "heap" Heap is a special tree structure in which each parent node is less than or equal to its child node.  then it is called a Min Heap. if each parent node greater than or equal to its child node than it is called Max heap. heap is a memory which is allocated during runtime. the size of the heap depends on Random Access Memory (RAM). it can change the size depending on the program.

Random Access Memory for any program is allocated by the underlying Operating system. On the top of the Operating system, a raw memory allocator oversees whether enough memory is available to it for storing objects. On the top of the raw memory allocator, there are several object-specific allocators operate on the same heap. 



                        Allocation of memory by Python's Virtual Machine (PVM)






Post a Comment

0 Comments