Memory leak when scanning the grid graph that has changed its center and dimension via script?

I am using 4.3.43 version, and my unity version is 2020.3.5f1 Personal. This is happening while in editor mode.

To specify what I did, I called Scan function of the Pathfinder after changing the dimension and the center of the grid graph via script.

            AstarPath pathfinder = FindObjectOfType<AstarPath>();

            Vector2 center = FindObjectOfType<Map>().center;
            int width = (int)FindObjectOfType<Map>().size.x * 2;
            int depth = (int)FindObjectOfType<Map>().size.y * 2;

            pathfinder.data.Awake();
            pathfinder.data.gridGraph.center = center;
            pathfinder.data.gridGraph.SetDimensions(width, depth, 0.5f);
            pathfinder.Scan();

This script automated setting up the width / depth / center of the grid graph, but the error message suggests I may be leaking memory. So, I tried manually changing the width / depth / center via the inspector menu, and the error message never seems to pop up.

So, I think somewhere in the script while changing the grid graph manually, I’m updating something (Native Array?) that I don’t when I change the grid graph automatically. Is there any way I can resolve this issue? It would save me quite sum of time if I can automate it without worrying about memory leaks.

Hi

When are you doing this?
You should never have to call pathfinder.data.Awake(); yourself. That may cause previously loaded graphs to be discarded (and thus leak memory).

Thanks, I’ll try that.

Somewhere in the internet… I’ve read that I have to call pathfinder.data.Awake() before modifying some values via script. At least that’s what my note says (“Call …Awake() before modifying value”). So I didn’t think that line could be problematic.