Jump to content

Cancel subscriptions?


Recommended Posts

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?


Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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