Is there a way to call this Garbage Collector in-game?

Ahuramazda

Veteran
Veteran
Joined
Nov 9, 2012
Messages
262
Reaction score
131
First Language
English
Primarily Uses
RMMZ
I've been dealing with issues regarding periodic lag in my testing, and I've tried several plugins to help with it and make garbage collection happen more often, or toy with the Cache limit, stabilize the scenes... I've spent hours scouring code and attempting some google Kung-fu to no avail.

But there is something I have discovered that instantly stops the lag-like effects and screen tearing that happens when I use it, and it is the Garbage Collection button in the Dev Console when play testing. When I click it, it immediately makes me go back to 60 fps and the latency drops back to 2-4 instead of jumping all over the place in the 14-20 range.

There has been no plugin, code snippet, hint, help, or ANYTHING that helps the way clicking that button can do, and I cannot find where I could manually call that by script.... is what I am asking even possible since the console isn't technically part of RPG Maker and can only be accessed during a playtest?

Request.png

Description of the lag: it doesn't always hit at the same time, but usually starts around 4m 15s of testing and will last for about 20-30 seconds, and then will repeat every 5 minutes or so. It doesn't matter what scene I am in at the time, the lag will come and go almost like clockwork. While dropping 5-7 fps doesn't sound like a lot, it is VERY noticeable to me and the 2 testers I have, esp when it can go down and up every other frame for the duration of whatever is happening, making a severe movement stutter that is visible easily.
 

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
708
Reaction score
638
First Language
English
Primarily Uses
RMMV
There is no way of calling the garbage collector in JavaScript unfortunately and its recommended to find out why the lag is happening to begin with. If you can find out the issue with lag then you should be able to fix it. It sounds like a possible memory leak, so your best option would be to do heap snapshots as well as a performance analysis to help you find any issues.

First thing I notice is that you're using an older version of MV, the dev tools you show in the screenshot tells me its below 1.6, my guess is 1.5 or possibly even lower than that? An upgrade very well may fix some of your lagging issues but it may not, it may be worth a try though. If you do try an upgrade, just create a backup of your project and try it out.
 

Ahuramazda

Veteran
Veteran
Joined
Nov 9, 2012
Messages
262
Reaction score
131
First Language
English
Primarily Uses
RMMZ
I have attempted an upgrade to 1.6+ but it broke far too many of my games plugins and systems so I am sticking with 1.5.1 to finish out the project as I have invested way too much time and effort for designing everything to stop cause of some lag issues.

Sadly I have no clue how to really do either of the two things you recommended, so it looks like I may have a tough learning curve in my near future. Thank you for the reply and I'll read up on those pages as soon as a I get a moment. :)
 

MrNybbles

Veteran
Veteran
Joined
Nov 6, 2019
Messages
59
Reaction score
31
First Language
English
Primarily Uses
RMMV
RPG Maker MV uses the V8 JavaScript Engine and if your package.json passes a specific flag (which it probably does) then it you can request Garbage Collection. (Note: This is a V8 feature, not something JavaScript normally allows).

You should check your 1.5.1 project's package.json exposes V8's Garbage Collection with the following line:
"js-flags": "--expose-gc",

If so then you can use the following code in the Dev Console (F8) or an event that executes JavaScript.
Code:
gc();
No really, that's it.

I also came across this function, but this should only clear the web cache:
Code:
window.nw.App.clearCache();

However, the cause of the problem really should be addressed. Your search-fu wasn't flawed, rather forced GC probably wasn't the answer to problems other people have had.

LTN Games' recommendations might seem daunting, but will give you the best picture of what is really going on under the hood (especially if a couple of Plug-ins are being naughty).

You could also try turning off all your Plug-ins, and enable them one at a time until you notice one causing lag. This might be less daunting, but if only one Plug-in is the problem then this could work.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,652
Reaction score
8,483
First Language
German
Primarily Uses
RMMV
@Ahuramazda

What you really should do is to think about "what is garbage" and how to prevent it. Unfortunately that is something too complex for a lot of plugin writers, which is why memory leaks happen.

Whenever you need a variable or an object or really anything that the computer needs to work with, it automatically assigns RAM to that variable or object. That is what the var command does, or the new command or a number of other commands depending on what you're doing and which language is used. For example if you want to display a picture then this will require enough RAM to hold the entire picture uncompressed and so on.
At some later time you no longer need to store that data - for example after the player confirms the picture and moves on, it is no longer needed.
A good programmer knows exactly when that happens and tells the computer to release the reserved RAM at that moment.
A lot of programmers unfortunately don't know how to do that and don't release the RAM - and the data becomes garbage instead.

The garbage collector is nothing but a function that checks if there are used RAM-sections that are assigned to variables or objects that no longer exists. If it finds such sections, they will be released and their RAM becomes available again for other functions.
Unfortunately the automatic is not perfect - in some cases the garbage collector can't determine whether a specific section is still in use or not. In such cases there is no choice but to leave that RAM blocked, because otherwise the garbage collector might crash the program by removing still vital RAM.
If however the RAM is indeed unused and the garbage collector simply can't determine that fact, then that RAM becomes a "memory leak" - memry that is permanently blocked from being used until the program ends (or crashes due to not enough free RAM).

So the best course is to find out which function uses up most RAM and then make sure that its RAM is manually released as soon as it is no longer needed instead of automatically release on garbage collection.
 
Last edited:

Ahuramazda

Veteran
Veteran
Joined
Nov 9, 2012
Messages
262
Reaction score
131
First Language
English
Primarily Uses
RMMZ
@MrNybbles

You should check your 1.5.1 project's package.json exposes V8's Garbage Collection with the following line:
"js-flags": "--expose-gc",

I actually have added that to the json file as one of my earlier tweaks while working on this, and had no clue calling it was so simple. I will save that as a final resort if I cannot find and solve the lag problems later today when I'm checking over everything. I really hope if it is a plugin it isn't one of the ones I have to absolutely keep for part of my games designs... there are about 6-7 of them I can get rid of because mechanically they add nothing, just icing on the cake so to say.

@Andar

Thank you for such a well made explanation as to what garbage actually is. I had understood it was leftover stuff that the system no longer needed, but I believed that it was ALL stuff that was no longer needed... not only stuff that was left behind by mistake by some potentially bad code. After reading your comment I realize I may have had the right idea of what to get rid of to fix my problem, but I was looking for the answer in a way that was just a band aid and not a true fix.

I will be keeping all the answers to this question in my mind while working today and hoping I can find the root for this sooner instead of later so it can be fixed in a proper manner :D
 

Latest Threads

Latest Posts

Latest Profile Posts

Working in the IT industry:
- "How long does it take?".
- "It takes 1 month".
- "What if we add more people to the project?".
- "It would take 2 months".
Doing RPG Maker News for 16th September 2021

Stream is live! I am currently doing pixel art and will be practicing shading! Feel free to drop by!
wow, Surface Tension is really one MF of an FPS level huh
So, I got let go from my current job because my skill set didn't align with the department's goals anymore. I have some hope, because I am currently in contact with a manager from a different department, and they are desperate for more employees. We'll see what happens... :kaoswt:

Forum statistics

Threads
115,120
Messages
1,087,368
Members
149,605
Latest member
Sedenho93
Top