-
-
Notifications
You must be signed in to change notification settings - Fork 89
Description
I load Intel Sponza Base using SharpGLTF and notice that even after a couple of minutes my application has a weirdly high RAM usage of 5GB:
![]()
Almost all of that comes from dead byte[] allocated by SharpGLTF:

Explicitly calling GC.Collect() is needed:

I'd rather not have my app keep Gigabytes of unused memory arround for no reason. SharpGLTF could make memory managment more transparent. We could focus on images only for now since those alone make up 2GB on this model.
As an example, currently all external images are loaded (even if the app never references them) into this managed byte[]. But this is not specific to external images.
SharpGLTF/src/SharpGLTF.Core/Memory/MemoryImage.cs
Lines 126 to 128 in 4b28af2
| filePath = System.IO.Path.GetFullPath(filePath); | |
| var data = System.IO.File.ReadAllBytes(filePath); |
I'd like to:
- Load images into my own memory
- Control when I load it
- Control if I load it at all
I don't know how other libaries handle this, but this is what I found fastgltf doing which has become quite popular recently: https://github.com/spnda/fastgltf/blob/7889b48e1435da943dcbeab5af4fbf7f39f1df0b/examples/gl_viewer/gl_viewer.cpp#L516-L555
Much more control is given to the user. I don't even need to make a copy. I can tell stbi image to load the image directly from the memory or file.