-
Notifications
You must be signed in to change notification settings - Fork 70
Description
Hey there, I've been investigating a memory issue in the SimpleHeap implementation and found that removed_node_tuples can grow indefinitely during pathfinding, especially on larger grids.
The problem is that when nodes are "removed" via remove_node(), they get added to removed_node_tuples but are never cleaned up. Over time, this set just keeps growing.
After digging into the code, I'm wondering if removed_node_tuples is actually necessary at all? From what I can see, the A* algorithm already marks processed nodes with the closed flag, so we could potentially simplify things by:
- Getting rid of
removed_node_tuplescompletely - Having
pop_node()just skip any nodes that are already closed - Making
remove_node()do nothing (or removing it entirely)
Something like:
def pop_node(self):
while self.open_list:
node_tuple = heapq.heappop(self.open_list)
# ... get node from tuple ...
if not node.closed:
return node
return None
I tested this approach and it seems to work correctly while eliminating the memory leak. The pathfinding results are identical, but without the growing memory usage.
Is there a specific reason removed_node_tuples was implemented this way, or would you be interested in a PR that simplifies this? I might be missing some edge case that requires the current approach, so wanted to check first.
Thanks!