InsOp Posted July 19, 2015 Share Posted July 19, 2015 Hello,I'm havingtrouble 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 guessit works everything fine relating to destroying objects in phaser.I came up with the idea to count all objects like thiscountChildren(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 More sharing options...
InsOp Posted July 21, 2015 Author Share Posted July 21, 2015 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._hasheven 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 setgame.world._hash.length = 0Or 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 More sharing options...
Recommended Posts