# How to solve the leak with DialogWindow::showModalDialog()?

**URL:** <https://forum.juce.com/t/how-to-solve-the-leak-with-dialogwindow-showmodaldialog/952>\
**Category:** General JUCE discussion\
**Created:** [July 24, 2006, 8:31am UTC](https://forum.juce.com/t/how-to-solve-the-leak-with-dialogwindow-showmodaldialog/952 "2006-07-24T08:31:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ring2](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@ring2](https://forum.juce.com/u/ring2)\
**Post date:** [July 24, 2006, 8:31am UTC](https://forum.juce.com/t/how-to-solve-the-leak-with-dialogwindow-showmodaldialog/952/1 "2006-07-24T08:31:53Z")

</div>

Hi there,

I’ve got memory leak message when my application quits after showing/closing the dialog window which is shown by DialogWindow::showModalDialog(). (Using JUCE v1.36.)

The content component is purely created by the latest Jucer with no specific methods/members are added.

Although I set a breakpoint at the destructor of the dialog, it’s never been stopped when the dialog is closed by clicking the close button and the dialog is closed. So the destructor is not called and all of the components in the dialog are never been freed.

The code displaying the dialog is simply

`DialogWindow::showModalDialog(T("Preferences"), new CPreferencesPane, this, Colours::lightgray, true);
`  
and it’s is called when the text button on another component is clicked. (this points that component, CPreferencesPane is exported by Jucer)

How should I free that dialog?

Best regards,  
Masanao Hayashi

---

<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 24, 2006, 8:51am UTC](https://forum.juce.com/t/how-to-solve-the-leak-with-dialogwindow-showmodaldialog/952/2 "2006-07-24T08:51:53Z")

</div>

If you read the help for showModalDialog(), you’ll see that it doesn’t delete the component you pass in (because you may want to use it again, or check its state after it’s been used). So just delete it when you’re done.

I usually do it as a stack object, which is neater - have a look in AudioDemo.cpp

---

<div class="post-metadata">

**Author:** ![ring2](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@ring2](https://forum.juce.com/u/ring2)\
**Post date:** [July 24, 2006, 9:03am UTC](https://forum.juce.com/t/how-to-solve-the-leak-with-dialogwindow-showmodaldialog/952/3 "2006-07-24T09:03:19Z")

</div>

Ah…! (I’ve just seen the AudioDemo.cpp)  
I was sorry for the stupid question… That’s my shame. :oops:

Masa

---

<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:01am UTC](https://forum.juce.com/t/how-to-solve-the-leak-with-dialogwindow-showmodaldialog/952/4 "2017-05-12T10:01:09Z")

</div>

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


