Jump to content

Cleaning up objects and variables in Phaser and Javascript


Recommended Posts

So, say I have this:

var some_objects = []

function create() {

    for(var i = 0; i < 10; i++){

        var graphics = game.add.graphics(0,0);
        graphics.beginFill(color, 1);
        graphics.drawCircle(0, 0, 50);




function kill(){

    some_objects.forEach(obj => {




Is this a good way to clean up/remove everything? The some_objects is still an array of 'somethings'. Do I need to also do something like this:

some_objects = []

Or is leaving some_objects an array, of what I think is empty references, okay to do?

I'm asking this because I don't want the game to slow down after a while because I'm not cleaning up my instances/objects/variables/whatever.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...