Jump to content

Memory management - Text


Husky
 Share

Recommended Posts

Hi All,

 

I'm having some problems with memory in my game and I believe it's related with how I create and destroy texts in my game.

 

To test it I created a small test app and I'm using the Chrome Developer Tools.

GameVar = {} GameVar.GameScreen = function (game) {}GameVar.GameScreen.prototype = {	create: function()	{		this.add.existing(new Phaser.Text(this.game,  Math.floor((Math.random()*600)+1), Math.floor((Math.random()*500)+1), "Test", {font: "14pt TepenoSans", fill: "#000000"}));	},    shutdown: function()  { },	update: function()	{		if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))	    {	    	this.game.state.start('GameScreen');	    }	    if (game.input.keyboard.isDown(Phaser.Keyboard.ENTER))	    {			this.add.existing(new Phaser.Text(this.game,  Math.floor((Math.random()*600)+1), Math.floor((Math.random()*500)+1), "Test", {font: "14pt TepenoSans", fill: "#000000"}));	    }	},};

This is how I'm doing the test:

 

1 - Enter the app

2 - Start recording on Timeline > Memory

3 - Press "Enter" for a few seconds

4 - Press "Space" to restart my "state"

5 - Press the Garbage Collector 

6 - Stop the recording

 

Using the dev tool I can see that some of my texts are still in memory.

 

Do I have to do something on "shutdown" function to free this texts?

 

Thanks in advance,

Felipe.

 

Link to comment
Share on other sites

Hi rich,

 

Thanks for answering .

 

In this case yes, I could re-use my texts objects. 

But on my app I have several states with lots of Texts (Help, Menu, Stats and in game HUD and texts) with different sizes and fonts.

 

Should I re-use this objects too?

 

Is there a way to force a "free" on Text objects?

 

Thanks again,

Felipe.
Link to comment
Share on other sites

A few more tests 

 

When adding inside a group after a change state all the texts are still on memory

//ADDING INSIDE A GROUPthis.screenElements = this.add.group();for (var i = 0; i < 5; i++) {     this.screenElements.add(new Phaser.Text(this.game, 500, 30 * i, "screenElements.add " + i));    };

When adding directly only the first text remains on memory after the change state

//ADDING DIRECTLYfor (var i = 0; i < 5; i++) {	this.add.text(0, 30 * i, "add.text " + i);};

And when I'm creating the texts and don't add in any group all the texts are removed from memory after a change state

//JUST CREATING BUT NO ADDINGthis.text0 = null;this.text1 = null;this.text2 = null;this.text3 = null;this.text4 = null;for (var i = 0; i < 5; i++) {	this["text"+i] = new Phaser.Text(this.game,500, 30 * i, "screenElements.add (var) " + i);};

Thanks,

Felipe.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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