2018-01-24 16:49:02

hi all
i have a problem with the garbage collector, actuely i don't know if it is a problem. exampels are the best way to explain, so take this one:

Total execution time: 144403 ms

WARNING: On 2863 occasions during the execution of your script, the garbage collector had accumulated so much content
so that it was forced to run a complete cycle to prevent an overflow. When this happens, severe lag occurs.

my two questions are:
is this a big number at small time?
how to avoid that?


Thumbs up

2018-01-24 18:06:00

I don't know anything about that as my knowledge of coding is very limited, but wat I can say is that's abou two and  half minutes time it seems like, unless my math is wrong, which is highly possible, because I suck at that as well, but yeah, in two minutes, it doesn't seem conceptually likely that you should be accumulating that much garbage that it needs to do that. You probably have serious problems with the way your thing is coded.

One of the best gifts on this earth is the unconditional love of an animal

It is pure, free of judgement, and raises me to the utter height of glory.

Thumbs up

2018-01-24 20:30:45

i remove some funcions  and include them with others but the problem still exist,
what i need to know really is the average per minute.

Thumbs up

2018-01-24 20:52:44 (edited by kianoosh 2018-01-24 20:55:21)

Hi there. It's good to know that if you use garbage collector where is not needed, You will encounter a bad lag you've never seen! Some people say you need to use it when you remove an object for example but in case of bullets, When they hit the player quickly their speed  goes down if you use the garbage collector before you remove the object or probably even after it.
I recommend use it when a dialog is beeing shown, a scene is beeing played or player is in process of changing their map because these cases are your best friends if you want to hide the lag from the player and meanwhile get a better performence.

Add me on skype: kianoosh.shakeri2
Or follow me on twitter @kianoosh shakeri

2018-01-24 23:09:58

This happens if you have an enormous Infant Mortality Rate, which is to say, way too many variables being destroyed in a frequently used function. An example that happened to me: I tried to base my geometry objects on a super-simplified version of Java2d, and Java is notorious for using objects for absolutely everything, even when methods would make much more sense. So, if I needed to do a test with a flipped or translated version of a shape, I'd have to make a new shape every time. At worst, this meant that a single frame of AI could result in hundreds of shapes being rapidly created and destroyed, just for one enemy to make one choice. Just 10 active objects could cause a garbage collector warning, if I let it play too long.
In my case, I became more willing to make shapes easily change from the interface, and tried to reuse a small set of them. This brought it down to double digits for the average scene, only getting into the hundreds when lots of projectiles were active at once. (I might also have used some not-entirely-thread-safe tricks in AI at one point. Not looking forward to porting that to a threaded language. sad )
So, if you are, say, creating a massive 3d array every frame, or something like that, that'd be the problem. Look for ways to accomplish the same things without creating so many variables, or so big arrays, etc. If you're having trouble finding where these variable graveyards are happening, maybe keep a global variable to count how many objects have been destroyed, and give your classes destructors that increment it? Ex, in an enemy class, you might do something like:
~enemy() { deadenemies++; }
Then set a key or command to report the value of deadenemies, or copy it to the clipboard every frame, or whatever works best for you.
At its worst, I was logging before and after all suspect bits of code, to try and hunt down exactly what was happening. I emphasize the value of backing up your code often, but especially in a situation like this, where it's easy to make so many changes while reducing the IMR that you accidentally break something and can't unravel how.
TLDR: look for places where you create too many temporary variables and objects on a frequent basis, and find a way to reduce that number.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

2018-01-24 23:42:12

yes this is my problem at last, 3d array of object handles.
thanks a lot

Thumbs up

2018-01-25 02:11:11 (edited by Ethin 2018-01-25 02:12:42)

I would also like to put forth the suggestion that you force the garbage collector to run a cycle as little as you can. Don't deliberately call garbage_collect() every 5 seconds or whenever a function ends, in a classes destructor, etc. In fact, I'd recommend you only call it if you know for a fact that the GC fails to clean up after and you know that that's the only way to erase your app's memory usage. The garbage collector is designed to be intelligent enough to scan for when objects are no longer referenced and when it's time to destroy them; let it handle that for you and don't try to handle it yourself. The only time you should have need to call the garbage_collect() function is if you know that your app uses a lot of memory at a certain point. Just beware that by the time that the game gets to calling the function the GC might've already ran a cycle for you.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

2018-01-25 15:29:24

i called the garbage collector after set the handles to null but the game continued even if it didn't clear all the garbage.

Thumbs up

2018-01-25 17:43:30

@8, it won't halt the game or anything when called. But you want to, at best, have the GC run on it's own. You usually shouldn't have to tell it to run a cycle via garbage_collect(). (At least, .NET's GC is incredibly intelligent and can determine when the best time to run itself is... not sure if BGT's is like that.)

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up