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.
-
Garbage collection: stackify.com/python-garbage-collectionL.Grozinger– L.Grozinger2020-02-18 11:16:04 +00:00Commented Feb 18, 2020 at 11:16
-
Does this answer your question? Releasing memory in Pythonmetatoaster– metatoaster2020-02-18 11:19:22 +00:00Commented Feb 18, 2020 at 11:19
Add a comment
|
2 Answers
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:
1 Comment
Akshada
exactly which variable will get deleted first?
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.