glTFast icon indicating copy to clipboard operation
glTFast copied to clipboard

Memory seems not fully released after disposing

Open GimChuang opened this issue 2 years ago • 2 comments

Describe the bug Hi, our app dynamically loads glb files from url. The code is attached below. When we destroy our gameobjects, we call GltfAsset..Dispose() and even ClearScenes() in OnDestroy(), but the memory seems not fully released and keeps being eaten up as we load and destroy more of them. We are using Unity 2022.1.10f1 + URP 13.1.8, building to WebGL, testing with Chrome. I was wondering if we missed something or there is a bug causing memory leak.

Files

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GLTFast;
public class TestGltf : MonoBehaviour
{
    GltfAsset gltfAsset;
    public string url = "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF/Duck.gltf";

    void Start()
    {
    }

    void OnDestroy()
    {
        if (gltfAsset != null)
        {
            gltfAsset.ClearScenes();
            gltfAsset.Dispose();
        }       
    }

    async void Load()
    {
        gltfAsset = gameObject.AddComponent<GltfAsset>();
        gltfAsset.LoadOnStartup = false;

        var success = await gltfAsset.Load(url);
        if (success)
        {
            if (!gltfAsset.CurrentSceneId.HasValue && gltfAsset.SceneCount > 0)
            {
                await gltfAsset.InstantiateScene(0);
            }
        }
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.L))
        {
            Load();
        }
    }
}

To Reproduce Steps to reproduce the behavior:

  1. Attach the script to a gameobject and make it a prefab
  2. Instantiate the prefab to scene
  3. Call Load()
  4. Destroy the gameobject
  5. Repeat 2-4. The memory will be eaten up gradually.

Expected behavior Memory gets fully released after calling Dispose()

Desktop (please complete the following information):

  • glTFast version: 5.0.0
  • Unity 2022.1.10f1
  • Render Pipeline and version: URP 13.1.8
  • Platform: WebGL

GimChuang avatar Feb 06 '23 05:02 GimChuang

Hi. Did you somehow solve the issue? Have you noticed any differences in behavior when loading .GLTF or .GLB models?

massimilianogaio avatar Mar 26 '23 10:03 massimilianogaio

Hi, unfortunately I haven't solved it. I didn't look closely in whether there's a different behaviour between loading .gltf and .glb. But they both produce the memory issue for me.

GimChuang avatar Mar 26 '23 10:03 GimChuang