# Leaked FileChooser when exiting application

**URL:** <https://forum.juce.com/t/leaked-filechooser-when-exiting-application/16386>\
**Category:** General JUCE discussion\
**Created:** [January 12, 2016, 6:59pm UTC](https://forum.juce.com/t/leaked-filechooser-when-exiting-application/16386 "2016-01-12T18:59:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![basteln](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@basteln](https://forum.juce.com/u/basteln)\
**Post date:** [January 12, 2016, 6:59pm UTC](https://forum.juce.com/t/leaked-filechooser-when-exiting-application/16386/1 "2016-01-12T18:59:08Z")

</div>

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&nbsp;with&nbsp;the&nbsp;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()) {
> 
> &nbsp; &nbsp; // do something with&nbsp;chooser.getResult()
> 
> }

I'm not holding on to the FileChooser anywhere else. I have had the same problem&nbsp;with AlertWindows, &nbsp;but I solved it there ModalComponentManager::Callback and showing the window asynchronously.&nbsp; 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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 13, 2016, 9:20am UTC](https://forum.juce.com/t/leaked-filechooser-when-exiting-application/16386/2 "2016-01-13T09:20:44Z")

</div>

This is why modal loops are EVIL!&nbsp;

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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 13, 2016, 9:21am UTC](https://forum.juce.com/t/leaked-filechooser-when-exiting-application/16386/3 "2016-01-13T09:21:34Z")

</div>

..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.

---

<div class="post-metadata">

**Author:** ![saintidle](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@saintidle](https://forum.juce.com/u/saintidle)\
**Post date:** [July 28, 2016, 5:41pm UTC](https://forum.juce.com/t/leaked-filechooser-when-exiting-application/16386/4 "2016-07-28T17:41:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![saintidle](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@saintidle](https://forum.juce.com/u/saintidle)\
**Post date:** [July 29, 2016, 7:28am UTC](https://forum.juce.com/t/leaked-filechooser-when-exiting-application/16386/5 "2016-07-29T07:28:45Z")

</div>

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

Thanks, John.

---

<div class="post-metadata">

**Author:** ![basteln](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@basteln](https://forum.juce.com/u/basteln)\
**Post date:** [July 29, 2016, 11:59am UTC](https://forum.juce.com/t/leaked-filechooser-when-exiting-application/16386/6 "2016-07-29T11:59:01Z")

</div>

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.
