What is the best practice when reassigning object variables, to maximise memory and CPU efficiency?
We all know object variables do not actually "contain" the object data, but they're just references.
If an object variable is reassigned, I understand the object data gets automatically cleaned up by some garbage collector, otherwise it would remain inefficiently "lost in the memory". Is this correct? And in the first case, is the cleanup process efficient? To make things more clear, let's consider this simple example:
list1 = list(range(0, 1000)) #Some long list
list2 = list(range(0, -1000, -1)) #Some other long list
list1 = list2
Now, list 1 references same object data of list 2, but what happens to the data previously referenced by list1 (with no variable referencing it anymore)? Would it be more efficient to explicitly erase the object before?
del list1
list1 = list2