soylomass Posted March 4, 2017 Share Posted March 4, 2017 In my game, I have some parent groups where I store other groups and/or sprites. When I destroy the children using .destroy, they are removed from the property children, but they stay in the property hash of the parent group, forever. Therefore the game's memory usage grows over time until crashing the browser. Is it normal for children not being removed from hash property? What is that property for? Thanks in advance EDIT: Found the cause. See last post. Link to comment Share on other sites More sharing options...
samme Posted March 4, 2017 Share Posted March 4, 2017 They should be removed from the hash when destroyed. That's weird. All the same, an ever-growing hash would have to be enormous to cause memory problems. If you're creating/destroying sprites very frequently, that might be the true cause. I couldn't reproduce this with a simple group of sprites, the hash length is always accurate: Link to comment Share on other sites More sharing options...
soylomass Posted March 4, 2017 Author Share Posted March 4, 2017 5 minutes ago, samme said: They should be removed from the hash when destroyed. That's weird. All the same, an ever-growing hash would have to be enormous to cause memory problems. If you're creating/destroying sprites very frequently, that might be the true cause. I couldn't reproduce this with a simple group of sprites, the hash length is always accurate: The game is this one You can check the hash of the food group using chrome console: window.game.state.states[this.game.state.current].foodGroup.hash.length And compare with the children property: window.game.state.states[this.game.state.current].foodGroup.children.length Yes, I'm creating a new food for every food that is spawned nearby, and destroying them after eaten or out of the fov. Shouldn't I do this? Link to comment Share on other sites More sharing options...
samme Posted March 4, 2017 Share Posted March 4, 2017 Oh, I see, it's a long-running game, that makes more sense. Have you tried using Group instead of SpriteBatch? Does foodGroup use physics? Link to comment Share on other sites More sharing options...
soylomass Posted March 4, 2017 Author Share Posted March 4, 2017 1 minute ago, samme said: Oh, I see, it's a long-running game, that makes more sense. Have you tried using Group instead of SpriteBatch? Does foodGroup use physics? Yes, I've tried. The physics are decoupled from the graphics. Every object has a body property where I store a p2 body, and destroy it when I destroy the parent. Link to comment Share on other sites More sharing options...
soylomass Posted March 4, 2017 Author Share Posted March 4, 2017 If there is a way to solve this without reusing objects, it would be better. As every entity has a lot of properties that I'd need to reset to reuse it (much harder than directly creating a new one) Link to comment Share on other sites More sharing options...
samme Posted March 4, 2017 Share Posted March 4, 2017 Try setting a breakpoint on addToHash to see what is actually adding to it. Step into your destroy call and see if it reaches removeFromHash. You can of course try foodGroup.hash.length = 0 Link to comment Share on other sites More sharing options...
soylomass Posted March 5, 2017 Author Share Posted March 5, 2017 1 hour ago, samme said: Try setting a breakpoint on addToHash to see what is actually adding to it. Step into your destroy call and see if it reaches removeFromHash. You can of course try foodGroup.hash.length = 0 I'll try that and report. Whats the use of hash by the way? Emptying it manually doesn't affect existing entities? Link to comment Share on other sites More sharing options...
soylomass Posted March 5, 2017 Author Share Posted March 5, 2017 Oops, I found the cause. Each time I created an sprite/group, I first created it and then added it to a parent group with group.add, but the child "parent" property always remained as world. I solved it by setting the parent parameter in the constructor method. Link to comment Share on other sites More sharing options...
samme Posted March 5, 2017 Share Posted March 5, 2017 Seems to be used for Arcade Physics collisions. Link to comment Share on other sites More sharing options...
soylomass Posted March 5, 2017 Author Share Posted March 5, 2017 Another note, if I move a group from one group to another one, with group1.remove and group2.add, when I destroy the child group at the end, it won't be removed from it's last parent's hash property (group2), so I had to set group2.hash.length = 0 after moving a child. Link to comment Share on other sites More sharing options...
samme Posted March 7, 2017 Share Posted March 7, 2017 I love the deeeep animals Link to comment Share on other sites More sharing options...
soylomass Posted March 10, 2017 Author Share Posted March 10, 2017 On 7/3/2017 at 1:24 AM, samme said: I love the deeeep animals Thanks, it was a moment of inspiration where all the designs came to my mind, haha. I'm more a programmer than a designer. Link to comment Share on other sites More sharing options...
Recommended Posts