#Memory Leak
1 messages · Page 1 of 1 (latest)
What exactly is the thing you are loading? Maybe you are not disposing of it properly.
Memory Leak
What is an "AssimpContext"?
AssimpContext = new() create big native memory
assimp aka the c++ 3d importer (that even unity uses). im using a c# wrapper of it
but it doesnt matter. consider we have a native array (non managed)
and we have afunction to dispose it from memory.
i cant do that from within the editor
you basically cannot release native memory apparently in the Editor
You should use this https://docs.unity3d.com/ScriptReference/AssemblyReloadEvents.html to detect the domain reload and dispose the data
nope still getting leaks
that is equivalent to System.AppDomain.CurrentDomain.DomainUnload btw. except its maybe cross platform but on windows its same thing
is there no way to debug memory in unity ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Assimp;
using System.Linq;
public class AnimationImporterForAI
{
public static AssimpContext importer;
public static SkinnedMeshAnimationSystem.AnimationClip zombieIdle;
public static SkinnedMeshAnimationSystem.AnimationClip zombieWalk;
public static SkinnedMeshAnimationSystem.AnimationClip zombieAttack;
public static Scene scene;
static AnimationImporterForAI()
{
System.AppDomain.CurrentDomain.ProcessExit += (s, e) => importer.Dispose();
System.AppDomain.CurrentDomain.DomainUnload += (s, e) => importer.Dispose();
if(importer == null)
{
UnityEngine.Debug.Log("init importer");
importer = new AssimpContext();
importer.SetConfig(new Assimp.Configs.KeepSceneHierarchyConfig(true));
importer.SetConfig(new Assimp.Configs.FBXPreservePivotsConfig(false));
}
}
}
the problem is "static class AnimationImporterForAI" gets called each play/reload
and so the importer gets null each reload
and so new memory gets created each play
the System.AppDomain.CurrentDomain.DomainUnload (or AssemblyReloadEvents.beforeAssemblyReload)
doesnt seem to be solving it.
have you verifed the Dispose is running at the expected time like this?
or maybe it worked, and its just unity default behavior to add new memory each play so i cant tell that it worked?
yes
it runs whenever a new play happen. so basically if you exit play mode it wont happen
and on the right instance? Maybe there's variable capture happening here but you are creating the instance after subscribing that lambda
the importer is actually private mb. so no
most likely this i guess. since when i looked now the memory is 1gb. it jumped from 2g to 1 when i was typing in discord. so maybe its unity doing its stuff and not mem leak anymore but i couldnt tell ?