# DocumentWindow is not removed from the array

**URL:** <https://forum.juce.com/t/documentwindow-is-not-removed-from-the-array/56282>\
**Category:** General JUCE discussion\
**Created:** [May 19, 2023, 2:06am UTC](https://forum.juce.com/t/documentwindow-is-not-removed-from-the-array/56282 "2023-05-19T02:06:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayra](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ayra/32/5775_2.png) [@Ayra](https://forum.juce.com/u/Ayra)\
**Post date:** [May 19, 2023, 2:06am UTC](https://forum.juce.com/t/documentwindow-is-not-removed-from-the-array/56282/1 "2023-05-19T02:06:33Z")

</div>

ok… I’m really going crazy and I don’t know how to fix it…

I have some windows on desktop and I want to delete them (and also to remove them from the OwnerArray that contains them), in the code below if I comment **windows.removeObject(window)** all windows are remove from desktop, while if I try after also to delete them “some” of them remain on desktop and are not removed from the array… why?

```auto
void WindowsManager::closeWindow(Window* window)
{
    ayra::ValueTree::visitAllChildren(engine.getProjectManager().windowsVT, true,
                                [this, &window](juce::ValueTree& child) {
        if ((int)child.getProperty(ayra::IDs::windowID) == window->getWindowID())
                engine.getProjectManager().windowsVT.removeChild(child, nullptr);
        });

    if (mml.lockWasGained())
    {
        window->removeFromDesktop();
        windows.removeObject(window); // if I comment this all windows are hidden
    }
}

```

---

<div class="post-metadata">

**Author:** ![Ayra](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ayra/32/5775_2.png) [@Ayra](https://forum.juce.com/u/Ayra)\
**Post date:** [May 19, 2023, 5:39pm UTC](https://forum.juce.com/t/documentwindow-is-not-removed-from-the-array/56282/2 "2023-05-19T17:39:31Z")

</div>

None has an idea of why? 🙃
