Sorry for maybe stupid questions and for my bad English 馃
How to stop, clear & destroy Matter.js instance and debug renderer?
I create matter-js instance and debug renderer at runtime and I tried to destroy it by this way:
Matter.Render.stop(this.debugRender); // this only stop renderer but not destroy canvas
Matter.World.clear(this.engine.world);
Matter.Engine.clear(this.engine);
Everything is working and looks like ok but is it right way?
And that about memory leaks and how properly to kill debug renderer including canvas.
Yeah this is the right way to reset, though you're right that it will not destroy anything from memory.
If you want to do that for the renderer, you should dereference the canvas fully:
render.canvas.remove();
render.canvas = null;
render.context = null;
render.textures = {};
Most helpful comment
Yeah this is the right way to reset, though you're right that it will not destroy anything from memory.
If you want to do that for the renderer, you should dereference the canvas fully: