MV/MZ How does memory and stuff work?

So I don't really know programming basics and I've been wondering if I add an additional property to something with plugins or during gameplay with scripts should I always get rid of that somehow? Like if my battlers have additional property, does everything get automatically "deleted" after the battle ends and then start from clean table when new battle begins? Or will it somehow use more memory (and what about save file space?) every time a new battle begins, if I don't somehow get rid of it? Like when those classes create new objects every time?
If you add a property to an object, the property will exist on that object for as long as the object exists. So if you add a property to a Game_Enemy, for example, it will remain until the enemy no longer does (which will be when the battle ends, since enemy instances don't persist beyond the battle scene). But if you add one to a Game_Actor, it will last the entire game because actors are never destroyed once they're created.

And obviously, the more things you add to persistent objects that are serialised in save files, the larger the saves will become. It's a pretty negligible addition, though; you'd have to add a staggering number of custom properties before you made it large enough to be particularly noticeable.
Just declaring variables or properties has negligible impact. Maybe a couple bytes in file size. The performance impact is in frequency of processes, which is why stuff like pathfinding and dynamic lighting, or parallel events without wait commands are such memory hogs. Calculations are being done every frame/few frames.

You also see memory usage spikes on game/map load when a bunch of processes are executing.
If you add a property to an object, the property will exist on that object for as long as the object exists. So if you add a property to a Game_Enemy, for example, it will remain until the enemy no longer does (which will be when the battle ends, since enemy instances don't persist beyond the battle scene). But if you add one to a Game_Actor, it will last the entire game because actors are never destroyed once they're created.

And obviously, the more things you add to persistent objects that are serialised in save files, the larger the saves will become. It's a pretty negligible addition, though; you'd have to add a staggering number of custom properties before you made it large enough to be particularly noticeable.

Ok cool, so the enemies get "deleted" after the battle. Yeah, I kind of assumed that putting some properties with a number can't increase any memory usage by anything more than a tiny amount, but I never know about stuff like that, like if they somehow stayed and you played through 30 hours of killing thousands of enemies.
If you're creating object instances on a scene and never deleting them you will see a gradual decrease in performance but it's not noticeable until you get into thousands of instances. The threshold depends on the player's PC specs.
Ok cool, so the enemies get "deleted" after the battle. Yeah, I kind of assumed that putting some properties with a number can't increase any memory usage by anything more than a tiny amount, but I never know about stuff like that, like if they somehow stayed and you played through 30 hours of killing thousands of enemies.
Memory leaks were a lot more of an issue in VX Ace, where creating objects but not disposing them meant the object persisted in memory for the duration of the game session. Javascript does smarter garbage collection.
Ok cool. I'll have to check up on this stuff at some point. It's kind of unclear to me what happens because of garbage collection, what the code has for manual deletions and if there's some effects that happen just because of basic JS functionality (other than garbage collection) or something.
Ok cool. I'll have to check up on this stuff at some point. It's kind of unclear to me what happens because of garbage collection, what the code has for manual deletions and if there's some effects that happen just because of basic JS functionality (other than garbage collection) or something.
This may be helpful. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Memory_management

Original thread: https://forums.rpgmakerweb.com/threads/how-does-memory-and-stuff-work.178067/