I'm trying to reimplement (once more... i know...) a simple network in python made of node classes that reference other node classes (their children), and I was wondering what would happen if I create a recursive network (node1 -> node2 -> node3 -> node1) and accidentally lose all references to any of the nodes.
Imagine I have the following code
class node():
def __init__(self):
self.children = []
def append(self, child):
self.children.append(child)
node1 = node()
node2 = node()
node1.append(node2)
node2.append(node1) # now the network is recursive
node1 = 0
# node1 is still referenced in node2.children so will not be deleted
node2 = 0
# now both node1 and node2 are not directly referenced by any variable
# but they are referenced by the two children instances
after the last line of code, all references to node1 and node2 are lost, but the memory originally allocated to the nodes sill contain a reference to themselves.
Would node1 and node2 still be destroyed?