My game's memory usage increases after every battle

Hello!

So, I'm having what I think is a weird issue, maybe you can set me straight. My game takes about 1GB of memory just to start up and then load the save file (in the tester, NOT in the deployed game, there it is quite a bit smaller).

That's fine, I figure, because it's getting ready, but my real issue is that every time I enter a battle my memory usage goes up by about 400-500k, and then slowly comes back down, but it doesn't come down ALL the way. This means I end up in a situation where after several battles I've slowly crept up into the 3-4gb range, and in one map in particular kept crashing the browser completely because I'm assuming I ran out of RAM.

I'll post my plugin list when I get to my computer, but has anyone encountered this before?
What kind of computer is it? How much space does it have?
In order to help you try to find the source of the crashing, I wanted to explain how RPG Maker handles loading and culling.
It actually has a pretty spartan method of handling this, basically loading things only when they are called upon and then culling everything not in use after a designated number of frames have passed since the last culling.
This culling method is handled through the PIXI renderer, and the number of frames are specified there. I'm not sure if they have made changes to PIXI's implementation since MV, but in MV I honestly found its garbage collection to be a bit too aggressive, likely due to the fact that the engine targets low end devices.

The second thing to keep in mind is that...yes, technically you might have "run out of RAM", but likely not due to hardware, but due to software. RPG Maker games are 32bit applications and therefore are limited to a maximum utilization of 4gb.

So what might be happening is that something is still being flagged as "in use" when exiting combat, and therefore is not being cleaned up by the garbage collection. This eventually makes you hit the 4gb limit and the software crashes because it cannot address more than 4gb of memory.

This could be caused by a number of factors. From a poorly programmed plugin to the way you are building your maps, to the types of plugins you are using.
1) What plugins are you using, if any?
2) Are you using any "Preloader" plugins?
3) Are you doing parallax mapping? Regardless of whether you are or not, can you please describe that "one map in particular" on how it has been constructed (size, events, tile size, any other pertinent information)? It always crashing on that map could be related to a different problem.

I've seen some Preloader plugins that are not well built, and basically stuff anything and everything you tell it to load into RAM and keep it there. Obviously not ideal.
I did not know about the 4gb max RAM thing! That actually might be the issue.

Okay, so first of all, it's a Lenovo x64 laptop with 8GB of RAM, so I understand it not handling things well, I just also recognized that the CTD was not supposed to be happening.

Here's my plugin list
1695081054101.png


I'm also using dashStaminaMZ by Caethyril, but that's in a common event, not a plugin.

There are no preloaders or parallax maps, which i know are common sources of memory issues. I'm going to start turning these off one at a time and see how the memory reacts
I got the crashes to stop by stopping a parallel event that ran a common event that alternated two sets of fire traps, but I think that was just pushing it over the edge because the memory issue is still there, it's just not killing it completely.

The map is 100x100 with 4 branching paths from the middle:
1695081823493.png
Be careful with parallel events - you should almost never have one without Wait commands in it, unless you specifically know it needs to be that way.

The things there that manipulate graphics are the lighting and the fog effects, so does turning those off have any effect?
The lighting is so ingrained in the maps that I honestly can't even get you that info. But I've also noticed that it isn't the battle that spikes the memory, it's when the map loads back in.

EDIT: Lighting and fog affect GPU by about 20% and CPU by about 5% but no noticeable affect on Memory
I think the most sensible idea is to just do some logical troubleshooting.

Turn your plugins off, make sure there isn't something with parallel events or your map settings that's c causing it.

If the game runs stably with no plugins, then you start turning them back on until you figure out what's causing it.
Okay, new discovery, once garbage cleanup happens the memory drops about a full GB, I stood still for a while while I was reading something and when I came back to it the memory was back to the way it was before I even started the game up.

Maybe I fundamentally just don't understand how I'm supposed to be using parallel events, I have them as all my traps because the "player touch" option doesn't go off when the player is under a movement route command, which I use for my block moving.
EDIT: Lighting and fog affect GPU by about 20% and CPU by about 5% but no noticeable affect on Memory
Unrelated, but more info on how the game handles rendering;
Lighting and fog generally tends to be a GPU bound process, so that utilization makes sense. Again, I am uncertain if things have changed in MZ, but in MV the GPU is woefully under-utilized, being almost entirely CPU bound (with some minor exceptions)
RPG Maker itself is a single core/single threaded process. Arthran did some fascinating tests that showed me that even though I have a much more modern CPU than his own CPU by nearly a decade, and I have triple the thread count, his CPU still outperformed my CPU due to a higher clock speed on a single core compared to my CPU.
This is also why when you use parallel processes, all of the parallel processes are being calculated on a single thread, which is why performance can tank quickly. It's also why, if you have have parallel processes tanking performance, the game is laggy and unresponsive, but your operating system itself still functions normally.

Anyways, back on track,
Ideally the garbage collection should be tuned to clean up relatively frequently (iirc in MV it was somewhere around every 5 seconds or 300 frames).
I really don't recommend playing around with garbage collection, but if you want to, try googling "RPG Maker PIXI garbage collection", you should find some reddit posts about what line you need to adjust in the PIXI.js file to change the garbage collection. But to reitterate, I really don't recommend doing that unless it's absolutely necessary. It's better to find the source of what is using so much memory and seeing if we can address that instead of making garbage collection more aggressive.

I'm not sure how Effektseer (or however it is spelled) handles it's particle rendering. It is possible that creating too many particles could create a bunch of garbage to be cleaned up in RAM, so if you are using a parallel event "fire trap" that is calling way too many the particle animations at once~maybe~ that could be a source of problem. However, I also have a hard time believing that to be true as animations are culled when they are outside the buffer of the camera (which I think the buffer is like 10 tiles or so) So the particle effects would only be relevant if the animations are being played near the camera.
Originally you stated that things were not being cleaned up after battle, so my starting place would be any plugins related to battle.

And to clarify, we are just disabling plugins to find the culprit, we are not saying to permanently disable them, so even if your lighting plugin is integral to your game, we just want to temporarily disable it to see if it's causing the problem.
Yeah I know, but I meant that the lighting plugin is being used in script calls so it literally wont play if that one is disabled, like, it's everywhere.

Good thing though, none of the other plugins is the culprit, just ran a new game with them all off and it still happens.

Also, yeah, not going to fiddle with the garbage collection, i'll overhaul the entire game if ive been doing something the wrong way before that.

Fire traps are also not emitting particles (at least I don't think), it is merely switching the used image for the fire from the wispy smoke in !Flame to the fire in !Other2.

I'm thinking it has to be something to do with parallel events because it doesn't just happen on the floor with all the fire, it happens on all the floors. I'm going to make a test room so i can start the game without the lighting and see how it reacts.
Awwwwww dangit, it's the lighting engine. I guess it's creating new lights every time the map loads back in. That's why it's so much worse with the fire traps on, it's more lights it's creating in memory.
That doesn't seem right. What lighting engine are you using? Maybe it isn't configured correctly.
Maybe I fundamentally just don't understand how I'm supposed to be using parallel events, I have them as all my traps because the "player touch" option doesn't go off when the player is under a movement route command, which I use for my block moving.
I know you narrowed it primarily down to the lighting plugin, but this also sounds problematic.

You should have one parallel event doing this, and it should have a Wait command in it.

If you have multiple events for this purpose, and/or they're running continually, that's potentially bad.
That doesn't seem right. What lighting engine are you using? Maybe it isn't configured correctly.

I haven't heard of it before, but doesn't necessarily mean it is bad. However, (at least in the RMMV post) they mentioned they made changes to PIXI to adjust GPU utilization. Sorry if it's a bit cynical of me, but I really don't trust hobbyist devs to be poking around things they don't understand. I can only hope that he knew what he was doing, but just upon first glance, this was a red flag to me.
I know you narrowed it primarily down to the lighting plugin, but this also sounds problematic.

You should have one parallel event doing this, and it should have a Wait command in it.

If you have multiple events for this purpose, and/or they're running continually, that's potentially bad.
Okay well you definitely don't wanna see my scene then because I have hundreds of spike traps in some areas checking if the player is on top of them, gonna have to rework that.

@Sword_of_Dusk I'm using QJ-Lighting, which works great aside from the fact it seems to be causing this issue.

@TheAM-Dol Ohhhhhh dang I didn't know the script mucks around with the PIXI, that makes more sense.
Okay well you definitely don't wanna see my scene then because I have hundreds of spike traps in some areas checking if the player is on top of them, gonna have to rework that.
Yeah, that's...at the very least, very inefficient.

You should have one event that checks for the player to be on a region ID.
@ATT_Turan I tried the region ID thing! Does that work when the player is being moved by a movement route? If so that's an easy fix for a thing I knew was an issue but was too green with this to figure out the solution for.
Okay well you definitely don't wanna see my scene then because I have hundreds of spike traps in some areas checking if the player is on top of them, gonna have to rework that.
This is definitely going to cause problems. So reworking it is a good idea.
One other idea is to just work with the spartan implementation of garbage collection. If you are worried about Ram usage, you could create purge hallways - hallways with little stuff happening on them (these hallways would be completely separate maps). Make sure it takes the same length of time to garbage collect as it would to travel from one side of the map to the other (with maybe a small buffer just in case), ensuring that garbage collection happens before loading the next map. It's like you see games with loading doors or hallways or whatever, it's the same concept, but kind of in reverse. We can't intelligently cull items from RAM, so let's just give the game time to do it on its own.
Putting this hallways before large maps would ensure that it would have maximum RAM headroom to reduce problems.
@ATT_Turan I tried the region ID thing! Does that work when the player is being moved by a movement route?
I have no idea what you're currently doing, but aren't you doing it while the player is being moved by a movement route?

Original thread: https://forums.rpgmakerweb.com/threads/my-games-memory-usage-increases-after-every-battle.161287/