BasomtiKombucha Posted March 4, 2015 Share Posted March 4, 2015 Hi,let's say I'm crating an interactive button. That means I need to listen to MouseEvents, or some kind of its equivalent that pixi has (I'm not sure how this works).The button exists for a while, and once I don't need it anymore, I remove it. My question is: do I need to remove the event listener/cancel subscription/whatever as well? Take a look at this code: var button = new PIXI.Sprite(texture);button.buttonMode = true;button.interactive = true;stage.addChild(button);button.click = function(data) { console.log("CLICK!");}stage.removeChild(button);button = null;Is it ok, or will it memory leak? Quote Link to comment Share on other sites More sharing options...
achexi Posted March 4, 2015 Share Posted March 4, 2015 Your method is correct, this is how it's normally done. Quote Link to comment Share on other sites More sharing options...
Sawamara Posted March 4, 2015 Share Posted March 4, 2015 Setting button to null does not delete the button though, be careful with that. The only way to get "rid" of it is to allow it to be garbage collected AKA removing each and every reference made towards it. But that is more of a general JS discussion, not exactly Pixi. Disabling the sprite's interactivity, as far as I know, removes the handlers too. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.