Doubly Linked List - Garbage Collection
I have created a doubly linked list. My list contains only 2 elements (suppose node1 and node2) and I want to delete the head pointer which points to the first node (node1) in th
Solution 1:
By del self.head
, you delete the reference to the node, not the node itself. By re-assigning, the reference to the node is lost. Normally, in both ways, there is nothing left pointing to the next node. In general, Python deletes something from memory as soon as there are no references to it. So, in your case both have the same result. I would prefer just reassigning, without deleting
PS: Of course, assuming that the references are not kept somewhere else in your code
Post a Comment for "Doubly Linked List - Garbage Collection"