Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a way to destroy the Stage and Createjs object completely. #913

Open
Akimyou opened this issue Oct 17, 2017 · 3 comments
Open

Need a way to destroy the Stage and Createjs object completely. #913

Akimyou opened this issue Oct 17, 2017 · 3 comments

Comments

@Akimyou
Copy link

Akimyou commented Oct 17, 2017

Hi.

I try to use Createjs in my SPA project. But in some page, I want to destroy Createjs completely.

I remove the DOM object and stage's children, event listeners.

Then there still have Detached DOM tree.

I have to manual set that stage.canvas = null; stage._eventListeners = null; ... , it can resolve this Detached DOM tree problem.

See that demo.

var backend = {}
var handle = {
   addA () {
       backend.domWrap = document.createElement('ul')
       backend.dom1 = document.createElement('li')
       backend.dom2 = document.createElement('li')
       backend.dom3 = document.createElement('li')
       backend.dom4 = document.createElement('canvas')
       backend.domWrap.appendChild(backend.dom1)
       backend.domWrap.appendChild(backend.dom2)
       backend.domWrap.appendChild(backend.dom3)
       backend.domWrap.appendChild(backend.dom4)
       document.body.appendChild(backend.domWrap)
   },
   addB () {
     backend.domWrap = document.createElement('ul')
     backend.dom1 = document.createElement('li')
     backend.dom2 = document.createElement('li')
     backend.dom3 = document.createElement('li')
     backend.dom4 = document.createElement('canvas')
     backend.domWrap.appendChild(backend.dom1)
     backend.domWrap.appendChild(backend.dom2)
     backend.domWrap.appendChild(backend.dom3)
     backend.domWrap.appendChild(backend.dom4)
     backend.stage = new window.createjs.Stage(backend.dom4)
     document.body.appendChild(backend.domWrap)
   },
   delA () {
     document.body.removeChild(backend.domWrap)
     destroyStage(backend.stage)
     destroyCreatejs(window.createjs)
     backend = null
     window.createjs = null
   },
   delB () {
     document.body.removeChild(backend.domWrap)
     backend = null
   }
}

function destroyStage (stage) {
  stage.removeAllChildren()
  stage.removeAllEventListeners()
  stage.canvas = null
  stage._eventListeners = null
}

function destroyCreatejs (createjs) {
  createjs.DisplayObject._hitTestCanvas = null
}

window.handle = handle

Want to have a right way to destroy the Stage and Createjs object completely.

2017-10-17 20 16 12

Thanks.

@adamantivm
Copy link

I've been profiling a nasty memory leak where the root cause is this as well. I'd love to have a proper way to get the createJs object properly cleaned-up.

@hilts-vaughan
Copy link

hilts-vaughan commented Jan 31, 2020 via email

@adamantivm
Copy link

Thank you for the suggestion! I hadn't though of that.
Unfortunately for my case that would be very difficult to do, as this is part of a very large React application.

I think I found a solution though. I found a way to properly clean-up the Stage object from outside it by doing the following:

myStage.enableMouseOver(-1);
myStage.enableDOMEvents(false);
myStage.removeAllEventListeners();
myStage.removeAllChildren();
myStage.canvas = null;
myStage = null;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants