MZ Problem of switching different picture display through command window button in javascript

Hello everyone! I'm learning how to write my own custom HUD in js.

I wrote three classes, in which Window_MainCityMapContainerView is loaded on the map scene.

JavaScript:
class Window_CustomMenuView extends Window_Command {

    proxy

    constructor() {

        const rect = {

            x: 176,

            y: 314,

            width: 200,

            height: 208

        }

        super(rect);

        this.setHandler("ok", this.clickOk.bind(this))

        this.setHandler("cancel", this.clickCancel.bind(this))

    }

    itemHeight() {

        return 30;

    }

    makeCommandList() {

        this.addCommand("Tavern", "Tavern", true);

        this.addCommand("Guild", "Guild", false);

        this.addCommand("Church", "Church", true);

        this.addCommand("Castle", "Castle", true);

        this.addCommand("HitchHouse", "HitchHouse", true);

        this.addCommand("OutsideTown", "OutsideTown", true);

    }

    clickOk() {

        console.log("ok: ", this.currentSymbol())

    }

    clickCancel() {

        console.log("cancel: ", this.currentSymbol())

    }

    select(index) {

        super.select(index)

        //console.log(this.proxy)

        if(this.proxy && this.proxy.__proto__.hasOwnProperty("selectIndex")) {

            this.proxy.selectIndex(index)

        }

    }

    drawText(text, x, y, maxWidth, align) {

        this.contents.fontSize = 20

        this.contents.drawText(text, 20, y, maxWidth, this.lineHeight(), 'left');

    }

}

class Window_CustomPictureView extends Window_Base {

    constructor() {

        const rect = {

            x: 502,

            y: 262,

            width: 552,

            height: 312

        }

        super(rect)

    }

    drawPicture(filename, x, y) {

        const bitmap = ImageManager.loadParallax(filename)

        bitmap.addLoadListener(() => {

            this.contents.blt(bitmap, 0, 0, bitmap.width, bitmap.height, x, y, this.contents.width, this.contents.height)

        })

    };

}

class Window_MainCityMapContainerView extends Window_Base {

    customMenuView

    customPictureView

    constructor() {

        const rect = {

            x: 0,

            y: 0,

            width: 1104,

            height: 624

        }

        super(rect)

        this.customMenuView = new Window_CustomMenuView()

        this.customMenuView.proxy = this

        this.customPictureView = new Window_CustomPictureView()

        //this.customPictureView.drawPicture("bg004a", 0, 0)

        this.addChildToBack(this.customMenuView)

        this.addChildToBack(this.customPictureView)

    }

    selectIndex(index) {

        console.log("select: ", index)

        this.customPictureView.drawPicture(`${index}`, 0, 0)

    }

}

By switching the buttons of the command window, you can obtain different indexes and then draw different pictures.

Then my question is, I use a proxy object in Window_CustomMenuView, will this cause a circular reference?

Sorry to bother you all during the working day, hope you all have a nice day.
I mean, technically yes. But that's not really a problem in any way, there are lots of circular references in the codebase already. It's only an issue if you try to convert an object to JSON, but you should never need to do that with windows.
I mean, technically yes. But that's not really a problem in any way, there are lots of circular references in the codebase already. It's only an issue if you try to convert an object to JSON, but you should never need to do that with windows.
Hello, thank you for your reply. When I wrote similar things in other languages that use reference counting to manage memory, someone told me that I need to set the proxy object to a weak reference, so I was a little worried about this before.

I'm not sure what kind of garbage collection method RMMZ uses to manage memory. Has garbage collection helped me deal with the circular reference problem?
I'm not sure what kind of garbage collection method RMMZ uses to manage memory. Has garbage collection helped me deal with the circular reference problem?
Yes, JavaScript has been using mark-and-sweep GCs for a long time now, it can deal with reference cycles with no issue.
Yes, JavaScript has been using mark-and-sweep GCs for a long time now, it can deal with reference cycles with no issue.
Ok, thank you.

Original thread: https://forums.rpgmakerweb.com/threads/problem-of-switching-different-picture-display-through-command-window-button-in-javascript.161162/