A* Pathfinding Project

Memory not released after destroy AstarPath


#1


First I create a empty sence whith a AstarPath Distable,
AstarPath setting like pic, load data fome cache, And Cache StartUp is enable.

After Start the Scene, the mono is 13.9mb

Then I click the Init button, the astarpath enabled and the cache loadsuccess. the mono is 55.5mb.

Then I click the Destroy button, DestroyImmediate the Astar and Call GC.Collect()
But the mono is 46.3mb

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Pathfinding.Util;
using Pathfinding;

public class Reload : MonoBehaviour
{
    public AstarPath astar;
    public Button init;
    public Button destroy;
    void Start()
    {
        init.onClick.AddListener(Init);
        destroy.onClick.AddListener(Destroy);
    }

    private void Init() {
        Debug.LogError("Init");
        astar.gameObject.SetActive(true);
    }

    void Destroy() {
        Debug.LogError("Destroy");
        DestroyImmediate(astar);
        ListPool<GraphNode>.Clear();
        ListPool<Int3>.Clear();
        ListPool<Vector3>.Clear();
        ListPool<int>.Clear();
        ListPool<float>.Clear();
        ListPool<ABPath>.Clear();
        ListPool<GridNode>.Clear();
        GC.Collect();
    }

    private void OnDestroy() {
        destroy.onClick.RemoveListener(Destroy);
    }
}


#2

Hi

Some things are probably in object pools. E.g. https://arongranberg.com/astar/docs/listpool.html

You can use this to clear a bit more memory

ListPool<GraphNode>.Clear();
ListPool<Int3>.Clear();
ListPool<Vector3>.Clear();
ListPool<int>.Clear();
ListPool<float>.Clear();
ListPool<ABPath>.Clear();
ListPool<GridNode>.Clear();

#3

I tried, but not work, My Version is 4.2.10


#4

Keep in mind that .net will allocate a bunch of other stuff the first time the code is run. Static variables, JITed code, etc.
If you try to load the scene multiple times at least the memory usage should not go up.


#5

I in out scene several times, and findout Pathfinding.AstarData:DeserializeGraphs alloc memory and not release

At start


after 10 times

I use UWA GOT and do the test in android


#6

Hi

Can you make sure to run System.GC.Collect() during that profile to make sure that garbage is not treated as persisted.