StandaloneFilterWindow AudioSettingsDialog memory leak


I'm trying to properly shutdown an app based on the standalonefilterwindow.

For the most part, all is well, however a particular problem is when I have the audio settings window open, and quit the app, it triggers this:

// doh! If you don't delete all your windows before exiting, you're going to
// be leaking memory!
jassert (desktopComponents.size() == 0);

I think I get what is happening here - I'm creating that audio settings window but then not clearing it out properly cause the function that creates it is still running when the application is quit.

What is the best way to close out that audio settings dialog? I'm figuring I will do it in deleteFilter of standalonefilterwindow, but I can't figure out exactly how to do it.

For reference, here is the audio settings creation code:

virtual void showAudioSettingsDialog()
        DialogWindow::LaunchOptions o;
        o.content.setOwned (new AudioDeviceSelectorComponent (*deviceManager,
                                                              true, true, false, false));
        o.content->setSize (500, 450);

        o.dialogTitle                   = TRANS("Audio Settings");
        o.dialogBackgroundColour        = Colours::lightgrey;
        o.escapeKeyTriggersCloseButton  = true;
        o.useNativeTitleBar             = true;
        o.resizable                     = false;


My first guess was to declare DialogWindow::LaunchOptions o; as a private variable of the filterwindow itself - then I could call something like o.content->removeFromDesktop() in the deleteFilter function.

I keep hitting different errors whenever I try things like that, and this is an area of c++ I'm fairly new to. I'm also looking at the OptionalScopePointer part of this ( - but not quite sure how to implement that.

Thanks for any pointers or areas I could research more on.

I have now realised that deleteFilter is not where to do this, I need to do it in the standalonefilterwindow destructor, probably before deletefilter is called.

FWIW - this happens in the Plugin Host as well.


I am going through trying different things...

This thread has some neat ideas, but I'm not sure what he means by 'unwrapped DialogWindow:showDialog()'.

Got it.

Added this to the scope of standalonefilterwindow:

ScopedPointer<DialogWindow> settingsDialog;

...then set the window to that in showAudioSettingsDialog()

settingsDialog = o.launchAsync();

I was going to try to quickly fix the Plugin Host, but looks like I need to look into the differences between launchAsync and runModal a little more.


Thank yall

In MainHostWindow.h

    ScopedPointer <DialogWindow> audioSettingsDialog;

In MainHostWindow.cpp

void MainHostWindow::showAudioSettings()

    DialogWindow::LaunchOptions o;
    o.content.setOwned (new AudioDeviceSelectorComponent(deviceManager,
                                                         0, 256,
                                                         0, 256,
                                                         true, true, true, false));
    o.content->setSize (500, 450);

    audioSettingsDialog = o.launchAsync();



That is all hacked together though by comparing with Standalongfilterwindow - if it is incorrect, please let me know, and of course, use at your own risk.

Thanks yall.

Ok actually - once I change any settings in the AudioSettingsDialog, I'm getting errors on quit, mostly due to scopedpointers or changelisteners related to the audiosettings. I also noticed it gives me errors when I quit after closing the settings dialog.


Would appreciate any pointers to what I might be fundamentally getting wrong.


bump. how are you supposed to remove modal windows such as the audio settings when the app quits with the window open?


You could use DeletedAtShutdown, though it's best to have them explicitly deleted by your own components so that everything closes down in the correct order.