From 9863c877ae5c9d9b7fb0bd3123d5db36494f8a5d Mon Sep 17 00:00:00 2001 From: Nick McIntyre Date: Fri, 17 May 2024 08:28:08 -0500 Subject: [PATCH] Fix p5.Graphics.remove() reference --- src/core/p5.Graphics.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/p5.Graphics.js b/src/core/p5.Graphics.js index 4d8e848ff1..81b6c3a795 100644 --- a/src/core/p5.Graphics.js +++ b/src/core/p5.Graphics.js @@ -320,8 +320,22 @@ p5.Graphics = class extends p5.Element { /** * Removes the graphics buffer from the web page. * - * Calling `myGraphics.remove()` removes the graphics buffer's canvas along - * with any HTML elements it created. + * Calling `myGraphics.remove()` removes the graphics buffer's + * `<canvas>` element from the web page. The graphics buffer also uses + * a bit of memory on the CPU that can be freed like so: + * + * ```js + * // Remove the graphics buffer from the web page. + * myGraphics.remove(); + * + * // Delete the graphics buffer from CPU memory. + * myGraphics = undefined; + * ``` + * + * Note: All variables that reference the graphics buffer must be assigned + * the value `undefined` to delete the graphics buffer from CPU memory. If any + * variable still refers to the graphics buffer, then it won't be garbage + * collected. * * @method remove * @@ -358,7 +372,11 @@ p5.Graphics = class extends p5.Element { * // Remove the p5.Graphics object when the * // the user double-clicks. * function doubleClicked() { + * // Remove the p5.Graphics object from the web page. * pg.remove(); + * + * // Delete the p5.Graphics object from CPU memory. + * pg = undefined; * } * *