Jump to content

How should i delete objects?


Tufan
 Share

Recommended Posts

Should i set variables to null after removing them? Is it a good practice?

I have 2 states: load and play. I want to delete "Loading..." text when switching state to play but loadingText variable is always Phaser.Text object if i dont set it to null.

My current code is:

var loadingText;

// load state

loadingText = game.add.text(...);

// ...end of load state

game.world.remove(loadingText);

game.state.start("play");

Should i set loadingText variable to null to free memory?

Link to comment
Share on other sites

You can't free memory directly in JS, you can only remove references.

In your case, setting loadingText to null makes no difference because the loadingText reference disappears once the function exits. It doesn't erase the object, which is still in game.world.children somewhere. After Phaser clears the world, there are no more references to the the text object and it eventually passes into oblivion.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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