Subhasish Dash
Subhasish Dash

Reputation: 219

How to reuse the WebGL context within a canvas?

I am trying to clear the contents of WebGL canvas.

Is it fine if I just delete the canvas element from DOM and create a new one, and most importantly, will it clear up all the resources and not cause any memory leak.

My scenario is that, I am getting images continuously via AJAX polling from the server every 20 seconds and using a hidden WebGL canvas to draw it and further using another canvas to show it perfectly.

Suggestions?

Upvotes: 1

Views: 987

Answers (1)

user128511
user128511

Reputation:

Basically no, if you just delete the canvas from the DOM there is no guarantee it will get freed in time to create a new one, after 8 or 16 of them you'll possibly get an error.

see How do I clean up and unload a WebGL canvas context from GPU after use?

Why can't you just keep reusing the same canvas or canvases?

Upvotes: 1

Related Questions