Don't release memory in menu

Hello,

I'm making a plugin where I add picture like this with tilemap.addChild(this.sprite);

Someone on this forum say that I should deference tilemap once I finished to use it with this :

var aliasTerminate = Scene_Map.prototype.terminate;Scene_Map.prototype.terminate = function() { aliasTerminate.call(this); tilemap = undefined;};The problem is, even when I go in menu this function seems to be called ! And so my pictures disappear...

How to solve this ? Thanks !
There is only 1 active scene at a time and even if you wouldn't clear your local tilemap reference, a new one would be created after exiting the menu. I would advise you to read about the observer pattern and implement it. Basically, you have your object data in $gameMap (which persists and is only created, once you switch maps) and the sprite as part of Spriteset_Map, which observes the background data.
Well, it seems pretty hard 😀

So $gameMap store the data of my picture like width, height... and Spriteset_Map store the sprite itself ?

And when I switch scene, the sprite is deleted ? So I need to keep the sprite alive, I'm right ?

So I just have to know when the user is going into the menu, and so save the tilemap in my script and restore it once he came back ?

Original thread: https://forums.rpgmakerweb.com/threads/dont-release-memory-in-menu.54675/