mitsuba-renderer / nanogui

Minimalistic C++/Python GUI library for OpenGL, GLES2/3, Metal, and WebAssembly/WebGL
Other
1.57k stars 196 forks source link

Example1.cpp appears to leak memory because of `RenderPass` #88

Closed LincolnSand closed 2 years ago

LincolnSand commented 3 years ago

I decided to stick logging into the ref counting and Object destruction. I also decided to put in a destructor for ExampleApplication. It properly hits a ref count of 0 and calls the destructor if RenderPass and ImageView are not used (ImageView internally uses RenderPass). If they are used, it fails to ever hit a ref count of 0 and "leaks" memory on program exit and never calls the ExampleApplication destructor. I tracked it back to a std::vector in RenderPass called m_targets that appears to be the reason that it holds these owning references on program exit. It appears this std::vector of ref<Object>'s is never cleared (hence destructing the elements) and so these owning references continue to persist.

I have not found a fix to this bug so far.

If this is intentional behavior, then it is unclear from the documentation and confusing from a user pov.

Hopefully this bug report is detailed enough. I can post exact reproducibility code if needed after some time (I'm quite busy).

wjakob commented 2 years ago

FYI, this reference cycle issue is now fixed in on master. For details, see https://github.com/mitsuba-renderer/nanogui/commit/77b8d98a90223d6e0eb72188a619fbb153ef6c47 and https://github.com/mitsuba-renderer/nanogui/commit/e3dcfc51a9473d71e8cfb4e7f3020c6219051e03.