I recently learned that when you delete a list in Python, the reference of this list gets saved up within an array and gets popped out when you initialize a new list.
I ran this in my regular interpreter:
l = [1,2,3]
l_id = id(l)
del l
g = [1,2,3]
id(g) == l_id # True
And as expected I got the right result.
I tried the same thing on my IPython interpreter, and got False
instead. Why does it happen? Is it better?
Python version: v3.7.0:1bf9cc5093
Ipython version: 7.5.0
Update
Its happend also with different lists:
l = [1,2,3]
l_id = id(l)
del l
g = [1,2,3,4,5,6,7,8]
id(g) == l_id # True
And its always happend, its not just a random thing that they gets the same reference
Update 2
I do know why this happend, i just want to know why its happend only on pure python interpreter and not on my ipython, and which one of those method is better for memory management
Update 3
As i can explain the reason that those list have the same id, i can not get why it is difference between ipython and python.
Look at the implemetation of List listobject.c.
As we can see there is an array of references, called free_list
. which the values of the array is the destroyed list objects, and the count numfree
for the array indexing. we can see that if there is more then 80 list deleted, the next one wont be saved in the array. so from those line we can say that my statement can be always true for any new python interpreter.
but i still can not find a reason for ipython to work like this