• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Memory utilization behaviour and array creation

H

Humanicat

Guest
TL;DR When creating and returning an array from a script versus creating it inside an instance, memory usage behaves wildly different; using a lot more memory and not going down after. This seems to only be an issue when stored in a data structure, which is then copied.

I have these large tables of data, implemented as a grid, in which I hold points over an uncertain (varying) amount of time. To make this easier to manage there are scripts involved with handling tasks for these points. More specifically I use a script to return new arrays populated with a point’s (x, y, z) components. A problem arises though when I store these arrays inside a data structure and copy them later.

The grid is rebuilt each step, removing the entries which are no longer needed, and copying over the ones which are still in use. It seems that this action coupled with the way the array was created introduces the behaviour. For when I do this, memory usage of the program keeps rising indefinitely if new points are added. Older points which are destroyed don’t appear to free up the same amount of memory which was allocated. Eventually the program crashes because it’s out of memory.

In contrast, when the same code is run (with the array creation script being substituted for hard code inside the instance), all memory is freed again once the points have been destroyed. The creation of the arrays with a script itself doesn’t seem to be the issue; the act of copying the data appears to introduce the effect. Additionally, the behaviour persists across 1.x, and YYC builds.

And this is where my question becomes fuzzy. Is this behaviour to be expected? Is there a way around it? Can it be fixed? Is there something in my approach which I am overlooking? Is there a different approach to this? Is it even possible to do this in the first place? It’d be nice to know what is roughly going on; as I haven’t found out much about it so far.
 
Top