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 leaks on windows when using tinyobj_loader_opt.h #283
Comments
@n8vm Thanks!
I'd like to go with this proposal. Exposing lfpAlloc to public interface(e.g. struct attrib_t) isn't a good idea. |
@n8vm Could you try It removes lfpAlloc dependency from public API and public struct definitions. I have confirmed at least clang AddressSanitizer on Linux does not report memory leaks. |
Hi @syoyo, Thanks for the quick response! There still appear to be several vectors still using lfpAlloc, and so I'm still leaking memory in Windows. If you remove this line, that should point out any remaining lfpAlloc's. tinyobjloader/experimental/tinyobj_loader_opt.h Line 1004 in da0b64f
After that point, we could probably remove the "lfpAlloc" folder from the "experimental" folder as well just to clean things up. |
lfpAlloc is mandatory for multithreaded parsing. Without it the performance slowdowns by 2x ~ 3x on modern multicore CPU(e.g. 16 core Threadripper) You can try other multithread-aware allocators, e.g. mimalloc https://github.com/microsoft/mimalloc (well-maintaned and may have less issues on memory leaks) and how it goes. |
Huh, the problem actually might go deeper than lfpAlloc... lfpAlloc definitely leaks the most memory, but there appear to be other leaks as well, so it might not be lfpAlloc that's to blame. To be honest, I'm not sure where these leaks are coming from. Investigating... Perhaps it has something to do with memory allocated on the heap by std::threads not being freed once that thread is joined/destructed? |
@n8vm I have added a flag to enable/disable lfpAlloc in tinyobjloader/experimental/tinyobj_loader_opt.h Line 1005 in 1369a85
How it goes when disabling lfpAlloc(i.e. using STL default allocator)? FYI at least ASAN on Linux does not report any memory leak when running |
Hello. I have a repo for loading/editing/saving .nbt files. Just saying. |
Describe the issue
After calling "parseObj", lfpAlloc appears to leak memory. This seems to occur when vectors using lfpAlloc are resized, especially during emplace / push_back. This memory leak can be significantly large when loading hundreds of OBJ files.
By simply removing the "lfpAlloc" from all std::vectors used in tinyobj_loader_opt.h, I no longer leak memory.
To Reproduce
Please attach minimal and reproducible files(source codes, .obj/.mtl files, etc)
See @ogrex 's comment on issue #153. Repro can be done by modifying the "viewer.cc" file to repeatedly load a moderately large obj file.
Expected behavior
On return, parseOBJ should free all existing allocations to "lfpAlloc::Node<lfpAlloc::Chunk<<>>".
Alternatively, lfpAlloc should be removed as a dependency of tinyobj_loader_opt.h entirely, as this seems to fix the memory leak. I do not notice a significant impact on performance by removing lfpAlloc, however, more testing might be required to validate this is true.
Environment
The text was updated successfully, but these errors were encountered: