0 votes
in Python by
Explain how does Python memory management work?

2 Answers

0 votes
by

The Python memory manager manages chunks of memory called “Blocks”. A collection of blocks of the same size makes up the “Pool”. Pools are created on Arenas, chunks of 256kB memory allocated on heap=64 pools. If the objects get destroyed, the memory manager fills this space with a new object of the same size

0 votes
by

Python -- like C#, Java and many other languages -- uses garbage collection rather than manual memory management. You just freely create objects and the language's memory manager periodically (or when you specifically direct it to) looks for any objects that are no longer referenced by your program.

If you want to hold on to an object, just hold a reference to it. If you want the object to be freed (eventually) remove any references to it.

def foo(names):

for name in names:

print name

foo(["Eric", "Ernie", "Bert"])

foo(["Guthtrie", "Eddie", "Al"])

Each of these calls to foo creates a Python list object initialized with three values. For the duration of the foo call they are referenced by the variable names, but as soon as that function exits no variable is holding a reference to them and they are fair game for the garbage collector to delete.

Related questions

0 votes
asked Jul 2, 2020 in Python by GeorgeBell
0 votes
asked Jul 14, 2020 in Python by GeorgeBell
...