1
0
Fork 0

Avoid leaking reference cycles

This commit is contained in:
Joris van Rantwijk 2024-07-06 16:13:34 +02:00
parent 4c6115fb2f
commit 6a75ffaf63
2 changed files with 7 additions and 3 deletions

View File

@ -115,6 +115,7 @@ class UnionFindQueue(Generic[_NameT, _ElemT]):
if node is not None:
node.owner = None
while node is not None:
node.min_node = None # type: ignore
prev_node = node
if node.left is not None:
node = node.left

View File

@ -610,7 +610,7 @@ class _MatchingContext:
# For each T-vertex or unlabeled vertex "x",
# "vertex_sedge_queue[x]" is a queue of edges between "x" and any
# S-vertex. The priority of an edge is 2 times its pseudo-slack.
self.vertex_sedge_queue: list[PriorityQueue]
self.vertex_sedge_queue: list[PriorityQueue[int]]
self.vertex_sedge_queue = [PriorityQueue() for _x in range(num_vertex)]
self.vertex_sedge_node: list[Optional[PriorityQueue.Node]]
self.vertex_sedge_node = [None for _e in graph.edges]
@ -623,9 +623,9 @@ class _MatchingContext:
for blossom in itertools.chain(self.trivial_blossom,
self.nontrivial_blossom):
blossom.parent = None
blossom.vertex_set.clear()
del blossom.vertex_set
blossom.tree_blossoms = None
#
# Least-slack edge tracking:
@ -1316,6 +1316,9 @@ class _MatchingContext:
self.delta2_enable_blossom(sub)
# Avoid leaking a reference cycle.
del blossom.vertex_set
# Delete the expanded blossom.
self.nontrivial_blossom.remove(blossom)
@ -1827,7 +1830,7 @@ class _MatchingContext:
# This loop runs through at most O(n) iterations per stage.
while True:
self._check_alternating_tree_consistency() # TODO -- remove this
# self._check_alternating_tree_consistency() # TODO -- remove this
# Consider the incident edges of newly labeled S-vertices.
self.scan_new_s_vertices()