I have the following code snippets
var myCanvas = document.createElement("canvas");
. . .
var myCanvasContext = myCanvas.getContext("2d");
. . .
I assume that it is taking some graphics memory. I’d like to free them after using it.
Will the following code snippets free them?
myCanvasContext = null;
myCanvas = null;
What is the best practice?
Thanks in advance for your help.
Assuming you’d actually added the Canvas to your document at some point, you will also need to remove the elements from the DOM using document.removeChild(myCanvas).
Setting the elements to null as you’ve done is also needed, if the variables will be staying in scope for a while.