Leaked FileChooser when exiting application


I'm using the FileChooser class to load files in my app.

When I quit the app (using Cmd+Q on Mac) while the FileChooser dialog is open, I get an assertion failure with the output:

JUCE v4.1.0

*** Leaked objects detected: 1 instance(s) of class FileChooser

JUCE Assertion failure in juce_LeakedObjectDetector.h:95

I'm using the FileChooser as a local stack variable, as described in the documentation:

FileChooser chooser(title, path, filePatterns);

if(chooser.browseForFileToOpen()) {

    // do something with chooser.getResult()


I'm not holding on to the FileChooser anywhere else. I have had the same problem with AlertWindows,  but I solved it there ModalComponentManager::Callback and showing the window asynchronously.  How can I solve this problem for the FileChooser?

Note that this only happens when running from Xcode. When I run the app from Finder, it quits without a crash.


This is why modal loops are EVIL! 

If the file chooser is open and running a modal loop, and during that modal loop the app quits, then your FileChooser object is not just leaked, but is actually left on the stack (!) along with all sorts of other vital things. Sadly, we don't have an async FileChooser yet, but we'll need to figure out a way to do that at some point.


..but one suggestion: have a look at how the Introjucer handles quitting - if it's in the middle of a modal loop, it uses a timer to reschedule the quit event, so that things can close cleanly before it happens.


Same thing for me.

Using an alert window with text box to capture a String from user (in an audio plugin)

When I force quit I get a leak.

I’m a bit confused as to handle this properly in an audio plugin context, any ideas?


Sorry for the novice question…
Where in the code is the Jucer’s quit behaviour?

Thanks, John.


It’s in the Projucer source code, in the file: Source/Application/jucer_Application.cpp lines 212-243. Have a look at the struct AsyncQuitRetrier and the systemRequestedQuit member function.