Answer the question
In order to leave comments, you need to log in
How does memory cleanup work in Python?
Good afternoon! We started studying Python in the 1st year of the university.
After 3 years of C++, it is fundamentally important for me to know how everything works under the hood.
The teachers, unfortunately, are young graduate students and know little themselves.
Please tell me if I remove an element from the list in any of the following ways: del x[1], x.pop[1], x.remove[1]. Will the data be stored in memory?
x = [1, 2, 3, 4, 5]
a = x[4]
x.remove(5)
print(a)
Answer the question
In order to leave comments, you need to log in
If there are no references to the object in memory (object reference count = 0 (actually not exactly 0, but this is already connected with the internal mechanisms of the interpreter, this should not worry us)) - the object is deleted by the garbage collector. You don't have to worry about deleting objects.
Those. in your example, references to the object still remain (a = x[4]) , so the object is not automatically deleted.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question