Memory Leak when using AStar

  • A* version: 2.5.4
  • Unity version: 2022.3.22f1

So we are experiencing a memory leak when switching scenes (Game scene to Menu scene).
The A* GameObject is a prefab, and lives inside the Game scene. The Memory profiler unfortunately does not tell us more specifically what the issue is, but when A* is disabled, the issue does not occur.

It isn’t necessarily something inside A* directly, but rather it may be our usage of it as well? I know it is not much to go on, but any ideas what could be causing this? (e.g. certain types of methods we shouldn’t call anymore past a certain point, which method calls would be possible culprits, what should we try to clean up / release in order to solve it?)

Not sure if this has something to do with it, but we also sometimes get “A Native Collection has not been disposed, resulting in a memory leak.” inside the editor outside playmode. Your plug-in is the only code that uses unmanaged memory from the project-side as far as we know, so we assume it comes from there?

Hi

If it’s the leak I think it is (hard to say, because you didn’t post a stack trace), this is a bug in the Unity collections package. Try updating it to a newer version (this may require an update of the unity editor, to be able to install more recent updates).

Do you mean the Editor error or the memory leak we are getting inside the build when switching scenes? Unfortunately, we don’t have a stack trace for either of them.

I understood that it was only a single thing “A Native Collection has not been disposed, resulting in a memory leak”?

This is what I’m referring to.

We have a memory leak when switching scenes in the apk and editor.

We also sometimes get the beforementioned error, but I am not sure they are related at all. I just wanted to mention it in case. I will try what you suggested and see if that fixed it, but even if the error message is fixed, the memory leak I mentioned may still be unrelated to that particular issue.

Try to upgrade first, to see if that solves anything.