calipoop
calipoop

Reputation: 832

How to clean up canvas memory, and whether it even makes a difference?

Is there best practice or recommendations for cleaning up canvases (or canvi!) after you're done using them?

In particular, I have multiple canvi (off-screen) with multiple dataURLs (also off-screen). After manipulation, I generate a final image and no longer need the old dataURLs, etc.

Does it make a difference for me to go through each item setting them to null or ''? I'm already using anonymous vars for the canvi and dataURLs... Wondering if it's overkill or not.

Upvotes: 2

Views: 1476

Answers (1)

markE
markE

Reputation: 105015

The garbage collector will reclaim the memory of any javascript variables when they go out of scope.

This includes html elements which haven't yet been added to the DOM.

You can force an object to go out of scope by setting all references to it to null.

If you use multiple offscreen canvas elements, you can save memory by reusing any canvas elements that are no longer needed.

Upvotes: 2

Related Questions