brentstrandy Posted September 23, 2016 Share Posted September 23, 2016 I simply want to know the best approach for destroying a group and everything within the group. According to the documentation: destroy(destroyChildren, soft) Destroys this group. Removes all children, then removes this group from its parent and nulls references. Unfortunately, I'm still finding that my references return an object - not null or undefined For reference, here is a simplified look at the object I'm trying to destroy: class MyObject extends Phaser.Group { constructor(game) { this.game = game; // Creating Phaser sprites and adding them to group } destroyObject() { this.destroy(); } } Link to comment Share on other sites More sharing options...
DegGa Posted September 23, 2016 Share Posted September 23, 2016 If you want to destroy it COMPLETELY, just write in the "destroyObject" method: this = null Link to comment Share on other sites More sharing options...
brentstrandy Posted September 23, 2016 Author Share Posted September 23, 2016 Unfortunately that is not possible in Javascript Reference: http://stackoverflow.com/questions/16924116/is-it-possible-to-set-to-null-an-instance-of-a-class-within-the-class Link to comment Share on other sites More sharing options...
DegGa Posted September 23, 2016 Share Posted September 23, 2016 Oh, thank you! Link to comment Share on other sites More sharing options...
DegGa Posted September 23, 2016 Share Posted September 23, 2016 Maybe you can set the instance of the class to null?? Link to comment Share on other sites More sharing options...
samme Posted September 24, 2016 Share Posted September 24, 2016 5 hours ago, brentstrandy said: Unfortunately, I'm still finding that my references return an object That's normal. If you have any references to the group itself, you can set them to `null` or let them pass out of scope. When no references remain it will get garbage-collected. Link to comment Share on other sites More sharing options...
Recommended Posts