Sign in to follow this  

How should i delete objects?

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;


Should i set loadingText variable to null to free memory?

Share this post

Link to post
Share on other sites
3 hours ago, samme said:

When you switch states the world gets cleared...

But the variable won't be cleared automatically, i think removing object would help a bit.



Share this post

Link to post
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 somewhere. After Phaser clears the world, there are no more references to the the text object and it eventually passes into oblivion.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.