Threading Stalls, GCollector?

BlitzMax Forums/BlitzMax Programming/Threading Stalls, GCollector?

BLaBZ(Posted 2010) [#1]
Since I added threading it seems like every time the garbage collector decides to do it's thing the game stalls, is this normal?


ziggy(Posted 2010) [#2]
You can try to improve the reusability of already created objects, and also a pre-frame adaptative delta-timing usually help making this unoticeable.

I've used this in several games and it works very well, as it calculates automatically the deltatiming factor in a per-frame basis, so if a frame takes longer, the game just 'drops' frames.


ima747(Posted 2010) [#3]
The garbage collector seems wonky with multithreading in a lot of ways currently in my experience. Even with delta timing the spikes can get quite nasty and frequent depending on how you're using memory. Personally I've resorted to turning off the garbage collector and do a GCCollect() every 10th of a second or so whenever it's safe (I.e. When no threads are mallocing or doing anything else very memory intensive that is going to cause troubles)

It's far from a perfect solution but with the current issues (see also create/clear images causes ram to climb and never clear) it's the best I've found at the moment.


Gabriel(Posted 2010) [#4]
Building on what Ziggy said, if you do use a good timing system, with a fixed update, you can set your update rate very low (eg: 10 updates per second) and then use tweening to keep the visual updates supersmooth. Obviously, this won't work if you're creating a physics-heavy game which requires a high update rate, but on fairly undemanding casual games, it's more than enough. Because the update frequency is so infrequent, you can empty the garbage collector in your update code (not in your visual update) and the spikes will have less effect.


Sledge(Posted 2010) [#5]
You can try to improve the reusability of already created objects
This times a billion. I've come around to the idea that it should be a priority of the game(play) loop that it actively avoids creating garbage for the GC to chew on (do that stuff between levels instead). If you're dereferencing objects during gameplay then you're doing it wrong -- don't compensate with an over-engineered timing 'solution'; just stop doing it wrong! ;)


Sledge(Posted 2010) [#6]
DP (Ooh I don't get many of these!)


BLaBZ(Posted 2010) [#7]
@Ziggy Omg! Recycling Objects, since I implemented it, my games running twice as fast! Brilliant =D