When I implemet the dequeue() method, and in the following code
def dequeue(self):
if self.is_empty():
print("The Queue is empty")
return
answer = self._head._element
#---------------------
self._head = self._head._next #here, what happens with the "lost" node, because i think it is lost by the linked list
#---------------------
self._size -= 1
if self.is_empty():
self._tail = None
return answer
Is that node retrieved by the garbage collector?
, because when i lost the reference to that node, and i have no way to access it.
The node is implemented as following within a LinkedList class.
class _Node:
__slots__ = "_element","_next"
def __init__(self, element, next):
self._element = element
self._next = next
Yep, it's a notation, and the garbage collector knows when to retrieve unused data.