0
Assignment of objects in Python
Objects - on the heap Operation required-assignment (=) Assumptions - 1 objects will be moved from heap to stack for the assignment 2 obj1 has 6 properties obj2 has 7 properties Expected -MEMORY LEAK Is this correct ?
4 Respostas
+ 1
+ 2
Volodymyr Chelnokov does the assignment occur on the stack..
If so how does the garbage collector work? AFAIK this is on the heap... 🤔
+ 1
If you think in terms of C, you can treat any Python variable as a pointer to PyObject. So object assignment is a pointer assignment.
For getting rid of memory leaks Python has a garbage collector - any object that is not reachable (i. e. your program has no way of reading or modifying it in the future) is destroyed.
+ 1
Sanjay Kamath all variables live on heap. Python stack is not the same thing as machine call stack - it is just a linked list of PyFrameObject structures, which also live on the heap. You can watch https://m.youtube.com/watch?feature=youtu.be&v=smiL_aV1SOc for information on it
The only things that live on machine stack are internal variables of the interpreter.