How to shutdown Juce or free remaining Juce memory?


#1

I'm using JUCE v3.0.7-12-g0c1f2a6.

Part of the tests that I run on my applications is to run in valgrind and confirm that everything continues to look good.

But now that I've added some JUCE to my app, I see valgrind complain about memory "still reachable" after it exits.  This doesn't seem like leaks (there aren't many copies of the same blocks) but rather static initializations, or ...?

Regardless, I was wondering if there is a global JUCE shutdown, reset, or de-initialize function that I can call when my application is exiting to ensure a cleaner exit.

Some examples of the blocks valgrind is complaining about are (truncated to show just a few relevant lines):

==1== ...
==1== by 0x5EC262C: _dlerror_run (dlfcn/dlerror.c:163)
==1== by 0x5EC20C0: dlopen@@GLIBC_2.2.5 (dlfcn/dlopen.c:87)
==1== by 0x978924: juce::Desktop::Displays::findDisplays(float) (juce_linux_Windowing.cpp:3017)
==1== by 0x8F3565: juce::Desktop::Displays::init(juce::Desktop&) (juce_Desktop.cpp:335)
==1== by 0x8F321B: juce::Desktop::Displays::Displays(juce::Desktop&) (juce_Desktop.cpp:261)

==2== ...
==2== by 0x55DBA11: XkbTranslateKeySym (in libX11.so.6.3.0)
==2== by 0x55DBCB7: XLookupString (in libX11.so.6.3.0)
==2== by 0x9AD886: juce::LinuxComponentPeer::handleKeyPressEvent(XKeyEvent&) (juce_linux_Windowing.cpp:1355)
==2== by 0x9AD58E: juce::LinuxComponentPeer::handleWindowMessage(_XEvent&) (juce_linux_Windowing.cpp:1294)
==2== by 0x9ABCC4: juce::LinuxComponentPeer::windowMessageReceive(_XEvent&) (juce_linux_Windowing.cpp:850)

==3== ...
==3== by 0x557001B: XCreateGlyphCursor (in libX11.so.6.3.0)
==3== by 0x5570476: XCreateFontCursor (in libX11.so.6.3.0)
==3== by 0x979DF6: juce::MouseCursor::createStandardMouseCursor(juce::MouseCursor::StandardCursorType) (juce_linux_Windowing.cpp:3364)
==3== by 0x98486A: juce::MouseCursor::SharedCursorHandle::SharedCursorHandle(juce::MouseCursor::StandardCursorType) (juce_MouseCursor.cpp:49)
==3== by 0x9849F8: juce::MouseCursor::SharedCursorHandle::createStandard(juce::MouseCursor::StandardCursorType) (juce_MouseCursor.cpp:78)

==4== ...
==4== by 0x55DBA11: XkbTranslateKeySym (in libX11.so.6.3.0)
==4== by 0x55DBCB7: XLookupString (in libX11.so.6.3.0)
==4== by 0x9AD886: juce::LinuxComponentPeer::handleKeyPressEvent(XKeyEvent&) (juce_linux_Windowing.cpp:1355)
==4== by 0x9AD58E: juce::LinuxComponentPeer::handleWindowMessage(_XEvent&) (juce_linux_Windowing.cpp:1294)
==4== by 0x9ABCC4: juce::LinuxComponentPeer::windowMessageReceive(_XEvent&) (juce_linux_Windowing.cpp:850)

Thanks!

Stéphane


#2

If you're not letting juce itself manage the app startup/shutdown code, then you'd need to use something like the ScopedJuceInitialiser_GUI or shutdownJuce_GUI()