Zini Sorry for the confusion. By Astar node I don't mean the Godot node but the data structure "node" that the Astar algorithm uses. I'm calling it Astar node because that seems to be the general nomenclature when talking about Astar
Here's the relevant code:
In pathfinding.gd I'm creating nodes with
neighbor_node = NodeAstar.new({"tile": neighbor_tile})
This is the NodeAstar class (with only the relevant code to the issue)
extends RefCounted
func _init(properties):
tile = properties.tile
## Previous node which connected to this node
var previous_node: NodeAstar
var neighbors: Array[NodeAstar] = []
The nodes are stored in an array2D. Relevant code below:
extends RefCounted
var grid: Array = []
var grid_width: int
var grid_height: int
func _init(grid_width, grid_height):
self.grid_width = grid_width
self.grid_height = grid_height
for i in grid_width:
var column_array = []
for j in grid_height:
column_array.append(null)
grid.append(column_array)
func reset_values(reset_value):
for x in grid_width:
var column_array = []
for y in grid_height:
grid[x][y] = reset_value;
And I'm calling the reset_values method before running the pathfinding function
var node_grid: Array2d
# reset is called before the pathfinding function. This will set all values of node_grid to null
node_grid.reset_values(null)
I realize setting all values to null might not be the best approach here but I want to understand why there is a memory leak. The NodeAstar objects do reference each other in previous_node and the neighbors array. Is it because of that?
If I change NodeAstar to extends Node, and then call queue_free in reset_values then the memory leak issue is resolved.
Should I go ahead with using Node in this scenario without adding them to the scene tree?