When creating arrays in javascript and then removing all the pointers to that array, the garbage collector will eventually free the memory used by the array. The problem is that in a game where you want a stable framerate, the garbage collection could cause frame rate stuttering.
To prevent these fps drops, I want to create the array in advance, but the problem is I don't know how large the array should be. I Assume, starting with a array of 0 length and then increasing it would cause memory to be assigned and freed, as the array fills up, but will reducing the length of the array using operations like pop() or setting the length of the array to 0 cause re-assignement of memory and give work to the garbage collector?
let someArray = [];
// ... Inside game loop...
someArray.push(newElement); // Here memory might be re-allocated if the array increases too much.
// ...
someArray.length = 0; // Could this cause the array to be re-allocated to a smaller chunk of memory? Could this trigger garbage collection?