Jump to content

Delete all Objectreferences in Phaser


InsOp
 Share

Recommended Posts

Hello,

I'm having

trouble with Memory leaks.

 

This is why I have some scenarios im having questions about

 

s1:

var group = game.add.group();var sprite= game.add.sprite(0, 0, 'sprite');group.add(sprite);group.destroy(true,true)

s2:

var group = game.add.group();var sprite= game.add.sprite(0, 0, 'sprite');group.add(sprite);sprite.destroy();

s3:

same scenarious, but instead of the sprite object Im having primite graphics or text.

 

 

 

Now my Question: Will there still be a reference to that sprite-object? Or is it ready to be collected by the Garbage Collector?

 

Thanks in advance

 

PS: is there a way to check if a reference still exists in the phaser universe - maybe a function where i get back the sprite-object through the key?

 

 

Edit:

I guess

it works everything fine relating to destroying objects in phaser.

I came up with the idea to count all objects like this

countChildren(game.phaser.world.children);var countChildren = function(group){      var sum = 0;      for(var i in group){          sum += 1;          if (group[i].hasOwnProperty('children') && group[i].children.length>0){              sum += debug.countChildren(group[i].children);          }       }      return sum;     }

I always got back a constant value - so my memory leak has to be somewhere else ~~

Link to comment
Share on other sites

Okey, as i found out, my problem is phaser related.

for each created game object, there is an array which then is filled:

game.world._hash

even if you call the destroy method of a group or its children, this array still retains all objects.

-> Garbage Collector wont collect those objects, because there is still a reference existing.

This causes Memory leaks (and ultimately my game to crash because it sucks up too much memory).

 

Is it safe to set

game.world._hash.length = 0

Or is there another, better way in phaser to do this?

 

I really think its somehow my fault, since i cant imagine that im the first one who has this problem.

 

For what is this array needed anyways?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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