# How to get rid of a Desktop DocumentWind. on exit?

**URL:** <https://forum.juce.com/t/how-to-get-rid-of-a-desktop-documentwind-on-exit/1928>\
**Category:** General JUCE discussion\
**Created:** [July 22, 2007, 6:11pm UTC](https://forum.juce.com/t/how-to-get-rid-of-a-desktop-documentwind-on-exit/1928 "2007-07-22T18:11:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dasdeck](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@dasdeck](https://forum.juce.com/u/dasdeck)\
**Post date:** [July 22, 2007, 6:11pm UTC](https://forum.juce.com/t/how-to-get-rid-of-a-desktop-documentwind-on-exit/1928/1 "2007-07-22T18:11:16Z")

</div>

Hi all!

i (want to) create a extra desktop window like this:

[code]void Module::mouseDoubleClick ( const MouseEvent & e ) {

```
if (!moduleGUI) {
    moduleGUI = new ModuleGUI(this->getName(),Colours::lightgrey,
                               DocumentWindow::allButtons,
                               true);
    moduleGUI->setBounds(0,0,200,200);
    moduleGUI->setVisible(true);
	//getTopLevelComponent()->addAndMakeVisible(moduleGUI);

} else {
	//moduleGUI->removeFromDesktop();
    deleteAndZero(moduleGUI);
	//moduleGUI = 0;
}

```

}[/code]

and this double click toggleing works nice.

but if i exit the whole app via “JUCE::quit()” and the window is open, i get a juce error while debugging telling me some window has not beeing deleted:

`// doh! If you don't delete all your windows before exiting, you're going to
// be leaking memory!`

i added this to try to solve it  
(since the window is not added to a parent , it seems necessary to get rid of it manually [children get deleted aututomaticle do they?] ):

`Module::~Module() {
		if(moduleGUI )deleteAndZero( moduleGUI );
}`

i also tried to use “removeFromDesktop();” in some places and combinations of both wich brings me to another warning/erro

but his gives me a hint to make this command thread save and use the “MessageManagerLock”, wich i use like this:  
const MessageManagerLock mmLock;  
wich then brings me back to the other error.

where to delete it?  
pleas help me.

thanks.

D3CK

btw.: I really like the sytle of juce! you had java in mind? thanks for giving it to us.

---

<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:** [July 22, 2007, 7:28pm UTC](https://forum.juce.com/t/how-to-get-rid-of-a-desktop-documentwind-on-exit/1928/2 "2007-07-22T19:28:27Z")

</div>

Just delete it in the shutdown code of your JUCEApplication. Or make it inherit from DeletedAtShutdown to do it automatically. (Take a look at how the jucer and jucedemo handle this sort of thing). It’ll warn you about the messagemanager if you’re trying to delete it on another thread, which is a messy/inadvisable way to do it.

> [@](#):
>
> [children get deleted aututomaticle do they?] ):

No!

> [@](#):
>
> btw.: I really like the sytle of juce! you had java in mind? thanks for giving it to us.

Yes! And thx!

---

<div class="post-metadata">

**Author:** ![dasdeck](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@dasdeck](https://forum.juce.com/u/dasdeck)\
**Post date:** [July 23, 2007, 8:23am UTC](https://forum.juce.com/t/how-to-get-rid-of-a-desktop-documentwind-on-exit/1928/3 "2007-07-23T08:23:41Z")

</div>

thanks jules. i wasn’t aware of the DeletedAtShutdown Class. i find giving pointers of all my children (and neverthele on the dektop) windows to the JUCEApplication class is a bit tedious. of course i tried to delete the children in the destructors with deleteAndZero, but this did not help (maybe i forgot a destructor, but there aren’t too much classes yet). so are there any disadvantages of just deriving form deleteAndZero? I have an idea how it works, so i think not. then i could derive almost everitign from it or is this bad?

thanks so far, i hope i can iron out my other rectangle ambigious problem too.

peace

D3CK

---

<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:** [May 12, 2017, 10:27am UTC](https://forum.juce.com/t/how-to-get-rid-of-a-desktop-documentwind-on-exit/1928/4 "2017-05-12T10:27:13Z")

</div>

Closed on May 12, 2017, 10:27am UTC


