Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory seems not fully released after disposing #570

Closed
GimChuang opened this issue Feb 6, 2023 · 3 comments
Closed

Memory seems not fully released after disposing #570

GimChuang opened this issue Feb 6, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@GimChuang
Copy link

GimChuang commented Feb 6, 2023

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 GimChuang added the bug Something isn't working label Feb 6, 2023
@massimilianogaio
Copy link

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

@GimChuang
Copy link
Author

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.

@atteneder
Copy link
Owner

Duplicate of #726 (or rather the other way around). Closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants