If we create 2 variables a followed by b, then how these variable gets destroy in python heap. We want to understand the memory management done by python interpreter.
Asked
Active
Viewed 429 times
1
-
Garbage collection: https://stackify.com/python-garbage-collection/ – L.Grozinger Feb 18 '20 at 11:16
-
Does this answer your question? [Releasing memory in Python](https://stackoverflow.com/questions/15455048/releasing-memory-in-python) – metatoaster Feb 18 '20 at 11:19
2 Answers
2
Simply putting, Python memory manager counts references to the existing variables and if reference count is equal to zero, garbage collector automatically de-allocates the space for that variable.
I'd recommend following resources to better understand the flow:

Giorgi Jambazishvili
- 743
- 4
- 15
0
Order is undefined as python has a garbage collector. To trace the order you may add a __del__
method which is known as a destructor method in Python. It is called when there are no references to the object and object is garbage collected.

Łukasz Ślusarczyk
- 1,775
- 11
- 20