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 Leak: Unable to completely remove a run-time loaded GLB from memory #726

Open
Tom-Render opened this issue Oct 31, 2024 · 2 comments
Labels
bug Something isn't working import Import of glTF files run-time
Milestone

Comments

@Tom-Render
Copy link

First, thanks for the magnificent codebase 😉, this issue has me completely stumped so I’m pretty confident it’s a bug. However, apologies in advance if it’s not and there’s some elusive means of clearing gLTFast’s memory use I’ve somehow missed in the included example project.

Describe the bug

Every time we load a new GLB model we can only partially remove it from memory. This seems to happen on every platform, but is particularly problematic for us on iPad, where our application will inevitably build up memory use over time and eventually crash. To clarify, each one of our models is optimised enough to be viewed individually but viewing them in sequence causes issues because we cannot completely remove their predecessors from RAM.

Files

A small example unity project (including a glb) which re-creates the issue and produces .snap files (unity memory snapshots) as evidence can be downloaded here: https://we.tl/t-jYf1k8LwRZ

To Reproduce

  1. Download the example project: https://we.tl/t-jYf1k8LwRZ
  2. Extract and open it in Unity 2022.3.51f1
  3. Open build settings and tick “Development Build”, then do a build
  4. Run the built executable, the example application will:
    1. Load an empty scene, then take a first memory snapshot.
    2. Additively load a new scene.
    3. Run-time load a glb inside of that new scene.
    4. Destroy the loaded glb and clear any references to it.
    5. Unload the scene the glb (and the script that loaded it) was in.
    6. Force a memory clean-up with Resources/UnloadUnusedAsset and GC.Collect.
    7. Take a second memory snapshot
  5. Wait until the application says, “Demonstration complete”. You can then close the application.
  6. There will be two new .snap files on your desktop, return to the Unity Editor and use Window -> Analysis -> Memory Profiler to import and compare the .snap files. For example, I get an additional 270mb of untracked memory from the second memory snapshot, when ideally both snap files would have the same memory use.

Expected behaviour

When the first and second memory snapshots are compared, memory usage should be nearly identical. We should be able to restore RAM usage to (roughly) the original amount it was before the GLB was loaded.

Screenshots

Capture

Desktop (please complete the following information):

  • glTFast version: 6.8.0 (From the Unity Registry)
  • Unity Editor version: 2022.3.51f1
  • Render Pipeline and version: Built-In Render Pipeline for 2022.3.51f1
  • Platform: Standalone (Windows, Mac, Linux), Windows 10
@Tom-Render Tom-Render added the bug Something isn't working label Oct 31, 2024
@Tom-Render
Copy link
Author

I realised my example above, crucially, doesn’t invoke GltfImport.Dispose, here’s a version of the project which does invoke GltfImport.Dispose: https://we.tl/t-dzLqJbvrGf

Sadly, the memory leak is still present even after invoking GltfImport.Dispose:

Capture

@Tom-Render
Copy link
Author

For the sake of completeness, I should also note that I've now tested the example project in Unity 6000.0.25f1 and the leak still occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working import Import of glTF files run-time
Projects
Status: Planned
Development

No branches or pull requests

2 participants