Memory leak in Array Flash target

Hi! I was working with tilesheet, and I was testing the tilesheetStage3d. I started noticing that if I had a lot of tiles on screen the frame rate drop every couple of seconds. I test the app in Scout and as you can imagine the garbage collector was kicking in every 3 seconds. I comment the tilesheetStage3d part, and the frame jumps were still there, so it was something in my code.

Long story short i found that the garbage was generated when I fill the array with data from the tiles.

toDraw[counter] = frameData[j];


toDraw[counter] =  frameData[j]+ ball.x()+ball.mVelocity.x*dt)

I don’t know why the array is generating garbage, I tested this this

 toDraw[counter] = frameData[j];


toDraw[counter] =  100;
frameData[j]+ ball.x()+ball.mVelocity.x*dt);

So I made another project with just two Arrays(Floats) one to write and one to read

 for (i in 0...size) 

I got the same anomaly. By accident I posted XD going to upload the test in short

Here you can see the garbage collector kicking in, in the browser the spikes are not so big but you can see the pattern exactly the same.

and the project can be found here

It’s not a memory leak if the garbage collector collects it.

Yes you are right its not a “leak”, but I’m sure arrays are not suppose to generate this amount of garbage if the size is not change. I’m just assigning values from one array to another.

1 Like

Ok, so I change my implementation to use openfl.Vector instead of Array, and is working as expected. No more garbage generated by assigning a value. Had to change the implementation of spritesheetStage3D to use Vector.

Is there a clean way to use Vector when I target flash and Array when I target the other platforms? I read that is not recommended to use Array in flash, but that makes the code really target specific

Vector should work on other targets, let me know if you have any problems

1 Like

Maybe a whole temporary array is created internally. It’s better to ask in Haxe’s (google) group for this issue.

It may be corrected already. You can try with the latest Haxe (nightly: ) .

1 Like

So Flash runs super fast with openfl.Vector, native runs slower than flash, and neko crashes at start.

Running native with arrays is faster than flash but not that much faster(Of course using Stage3d in flash).
I don’t know if this should be a surprise after all I’m just drawing a lot of stuff with minimal logic. Most of the work is done by the same GPU. I’m going to create a simple test with objective numbers, to be sure that the result are not alliterated by my code.

For the moment I’m using this fix

#if (flash)
typedef MyList<T> = flash.Vector<T>;
typedef MyList<T> = Array<T>;

sea_jackal going to try out your suggestion