DocumentWindow is not removed from the array

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?

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
    }
}

None has an idea of why? :upside_down_face: