MZ manually removing a window

hi! I've been trying to understand this problem that I'm having concerning the correct way to manually remove a window.
I've tried ".close" but this doesn't work and its very similar to ".hide" .

an example;
JavaScript:
Scene_GameEnd.prototype.createCommandWindow = function() {
    const rect = this.commandWindowRect();
    this._commandWindow = new Window_GameEnd(rect);
    this._commandWindow.setHandler("toTitle", this.commandToTitle.bind(this));
    this._commandWindow.setHandler("cancel", this.popScene.bind(this));
    this.addWindow(this._commandWindow);
};

//ive tried
this._commandWindow.close();
//and
this._commandWindow.hide();

but those don't work as I've noticed that global variables created by the window(intentional)get multiplied if I create the window afterwards.

any advice would be greatly appreciated, thanks in advance~
Hi there!
If you want to remove the window from the container, you can try call the destroy method:

myWindow.destroy()

Or you can search for it into the window layer children and remove it from there. I'm just not sure if you can do this like remove any regular element from an array, or if you need to use a proper method. Something like:

this._windowLayer.removeChildren(my window)
Hi there!
If you want to remove the window from the container, you can try call the destroy method:

myWindow.destroy()

Or you can search for it into the window layer children and remove it from there. I'm just not sure if you can do this like remove any regular element from an array, or if you need to use a proper method. Something like:

this._windowLayer.removeChildren(my window)
oh this helps lots, thanks very much~

Original thread: https://forums.rpgmakerweb.com/threads/manually-removing-a-window.148481/