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

[Question] How to completely destroy instances of TwoJS ? #734

Open
duping123456 opened this issue Jul 17, 2024 · 1 comment
Open

[Question] How to completely destroy instances of TwoJS ? #734

duping123456 opened this issue Jul 17, 2024 · 1 comment
Labels

Comments

@duping123456
Copy link

I have a Vue project that references this JS. In one of the pages, four graphics drawn by TwoJS were rendered. When I re rendered the page, the four TwoJs were not destroyed and were regenerated. This caused the memory to constantly increase every time I switched data and re rendered the component, until the webpage crashed

@jonobr1
Copy link
Owner

jonobr1 commented Jul 17, 2024

Ah yes, on unmount you'll want to do this:

const index = Two.Instances.indexOf(two);
const parent = two.renderer.domElement.parentElement;
if (index >= 0) Two.Instances.splice(index, 1);
if (parent) parent.removeChild(two.renderer.domElement);
two.release(two.scene);

Assuming your instance of Two.js is called two.

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

No branches or pull requests

2 participants