memory allocation with pythonall objects are stored in pool of memoryknown as the memory heap or python heap (which should not be confused with the "heapdata structure presented in when command such as widgetis executedassuming widget is the name of classa new instance of the class is created and stored somewhere within the memory heap the python interpreter is responsible for negotiating the use of space with the operating system and for managing the use of the memory heap when executing python program the storage available in the memory heap is divided into blockswhich are contiguous array-like "chunksof memory that may be of variable or fixed sizes the system must be implemented so that it can quickly allocate memory for new objects one popular method is to keep contiguous "holesof available free memory in linked listcalled the free list the links joining these holes are stored inside the holes themselvessince their memory is not being used as memory is allocated and deallocatedthe collection of holes in the free lists changeswith the unused memory being separated into disjoint holes divided by blocks of used memory this separation of unused memory into separate holes is known as fragmentation the problem is that it becomes more difficult to find large continuous chunks of memorywhen neededeven though an equivalent amount of memory may be unused (yet fragmentedthereforewe would like to minimize fragmentation as much as possible there are two kinds of fragmentation that can occur internal fragmentation occurs when portion of an allocated memory block is unused for examplea program may request an array of size but only use the first cells of this array there is not much that run-time environment can do to reduce internal fragmentation external fragmentationon the other handoccurs when there is significant amount of unused memory between several contiguous blocks of allocated memory since the run-time environment has control over where to allocate memory when it is requestedthe run-time environment should allocate memory in way to try to reduce external fragmentation as much as reasonably possible several heuristics have been suggested for allocating memory from the heap so as to minimize external fragmentation the best-fit algorithm searches the entire free list to find the hole whose size is closest to the amount of memory being requested the first-fit algorithm searches from the beginning of the free list for the first hole that is large enough the next-fit algorithm is similarin that it also searches the free list for the first hole that is large enoughbut it begins its search from where it left off previouslyviewing the free list as circularly linked list (section the worst-fit algorithm searches the free list to find the largest hole of available memorywhich might be done faster than search of the entire free list