#Memory Leak

1 messages · Page 1 of 1 (latest)

faint condor
#

What exactly is the thing you are loading? Maybe you are not disposing of it properly.

#

Memory Leak

whole mantle
#

im not disposing it at all. since disposing doesnt work.

#

its the AssimpContext

faint condor
#

What is an "AssimpContext"?

whole mantle
#

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

faint condor
whole mantle
#

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 ?

faint condor
#

There's a memory profiler

#

perhaps your method of disposing the memory is faulty

whole mantle
#
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.

faint condor
#

have you verifed the Dispose is running at the expected time like this?

whole mantle
#

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

faint condor
#

and on the right instance? Maybe there's variable capture happening here but you are creating the instance after subscribing that lambda

whole mantle
#

the importer is actually private mb. so no

whole mantle