# DocumentWindow crashes when exiting

**URL:** <https://forum.juce.com/t/documentwindow-crashes-when-exiting/60502>\
**Category:** General JUCE discussion\
**Created:** [March 19, 2024, 12:59am UTC](https://forum.juce.com/t/documentwindow-crashes-when-exiting/60502 "2024-03-19T00:59:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![morphism](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@morphism](https://forum.juce.com/u/morphism)\
**Post date:** [March 19, 2024, 12:59am UTC](https://forum.juce.com/t/documentwindow-crashes-when-exiting/60502/1 "2024-03-19T00:59:33Z")

</div>

Hello,  
My main window is  
class MainComponent : public AudioAppComponent, public Slider::Listener, public ComboBox::Listener, public TextButton::Listener, public TextEditor::Listener

I created another DocumentWindow as a Dialog Window inside that MainComponent

DocumentWindow\* combowindow = new DocumentWindow(“ComboWindow”, Colour::Colours::white, DocumentWindow::allButtons, false)

Also I created a component

Component combocontent;

I inserted several buttons, text editors etc inside that combocontent

And

```
combowindow->setContentOwned(&combocontent, false);

```

So I use this combowindow as a dialog popup window

But, when I exit this program

delete combowindow;

This causes crashes

So I tried

```
combocontent.removeAllChildren();

combowindow->clearContentComponent();

```

It does not work. The program crashes

+++++++++++++++++===================================\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
More precisely it crashes here

void ResizableWindow::clearContentComponent()  
{  
if (ownsContentComponent)  
{  
contentComponent.deleteAndZero();  
}  
else  
{  
removeChildComponent (contentComponent);  
contentComponent = nullptr;  
}  
}

+++++++++++++++++===================================\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

So, could you please teach me how to handle this properly

Thank you

---

<div class="post-metadata">

**Author:** ![morphism](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@morphism](https://forum.juce.com/u/morphism)\
**Post date:** [March 19, 2024, 1:08am UTC](https://forum.juce.com/t/documentwindow-crashes-when-exiting/60502/2 "2024-03-19T01:08:54Z")

</div>

Hello,  
I found the coding below works OK now

```
combowindow->setContentNonOwned(& combocontent, false);

```

not the original

combowindow-\>setContentOwned(&combocontent, false);

So, could you please explain to me what is the difference and why this happens?

Thanks

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [March 19, 2024, 11:05am UTC](https://forum.juce.com/t/documentwindow-crashes-when-exiting/60502/3 "2024-03-19T11:05:26Z")

</div>

> [@morphism](#):
>
> So, could you please explain to me what is the difference and why this happens?

The differences are explained in the documentation for these functions. The “Owned” variant will call `delete` on the component once it is no longer needed, so should only be used with components created via `new`. The “NonOwned” variant will not delete the component.

The crash you’re seeing is likely because the ResizableWindow is attempting to delete an object that wasn’t created via `new`.

---

<div class="post-metadata">

**Author:** ![morphism](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@morphism](https://forum.juce.com/u/morphism)\
**Post date:** [March 19, 2024, 3:04pm UTC](https://forum.juce.com/t/documentwindow-crashes-when-exiting/60502/4 "2024-03-19T15:04:25Z")

</div>

Thank you. Have a nice day !
