This forum is read only and just serves as an archive. If you have any questions, please post them on

1 decade ago by vincentpiel


in any case anyone is interested, i wrote an article about pooling here:

Basically, pooling is recycling objects to avoid memory allocation / garbage collection.

I then applied this pattern to the ig.Classes, the article is here :

And the code is here :

Let me know if it happens to help you with your game !

1 decade ago by Joncom

Thank you for taking the game to write this up. Very interesting.
I have not yet found the garbage collection "hit" on performance to be too bad.
But I suspect I might at some point, and I'll have this article bookmarked. :)


Does this method improve performance by preventing garbage collection from taking place, and thus uses more memory?

1 decade ago by vincentpiel

Thx for your comments !
As for performances, yes pooling makes you both avoid memory allocation and garbage collection, which is noticeable with a big number of pooled objects.
For the memory use, sure you have to be careful : a too big pool juste waste memory for nothing. So one has to adjust, looking at the createdCount at the end of a game session. And obviously you might un-reference the pool at any time to have its memory reclaimed (i wonder if i should precise that in the post).

1 decade ago by John

I've tried using your plugin but keep getting this error {

Uncaught TypeError: Object function Class(){if(!initializing){if(this.staticInstantiate){var obj=this.staticInstantiate.apply(this,arguments);if(obj){return obj;}}
for(var p in this){if(typeof(this[p])=='object'){this[p]=ig.copy(this[p]);}}
return this;} has no method 'setupPool'
ig.Loader.inject.end loader.js:27
(anonymous function)
(anonymous function)


Any idea what's going on?

1 decade ago by vincentpiel

1) Are you sure you require() the module before using it ?
2) If you want to auto-pool entity (meaning : you don't have to change a thing to make it work if you are using only spawnEntity and kill with your entities)
you have to call ga.autoPoolEntities();

On the other hand, if you use pooling on an ig.Class which is not an entity, it will be your responsibility to create them using MyClass.pnew(...), and to dispose of the instances with myInstance.pdispose();

1 decade ago by John

Yes and yes, It's all working great now. My game runs faster and is no longer jittery on older devices. Thanks for your help.
Page 1 of 1
« first « previous next › last »