Skip to content

Commit f93bc32

Browse files
authored
Merge pull request #7057 from nickmcintyre/ref-p5-graphics
Fix p5.Graphics.remove() reference
2 parents f61cbbd + 9863c87 commit f93bc32

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/core/p5.Graphics.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,22 @@ p5.Graphics = class extends p5.Element {
320320
/**
321321
* Removes the graphics buffer from the web page.
322322
*
323-
* Calling `myGraphics.remove()` removes the graphics buffer's canvas along
324-
* with any HTML elements it created.
323+
* Calling `myGraphics.remove()` removes the graphics buffer's
324+
* `<canvas>` element from the web page. The graphics buffer also uses
325+
* a bit of memory on the CPU that can be freed like so:
326+
*
327+
* ```js
328+
* // Remove the graphics buffer from the web page.
329+
* myGraphics.remove();
330+
*
331+
* // Delete the graphics buffer from CPU memory.
332+
* myGraphics = undefined;
333+
* ```
334+
*
335+
* Note: All variables that reference the graphics buffer must be assigned
336+
* the value `undefined` to delete the graphics buffer from CPU memory. If any
337+
* variable still refers to the graphics buffer, then it won't be garbage
338+
* collected.
325339
*
326340
* @method remove
327341
*
@@ -358,7 +372,11 @@ p5.Graphics = class extends p5.Element {
358372
* // Remove the p5.Graphics object when the
359373
* // the user double-clicks.
360374
* function doubleClicked() {
375+
* // Remove the p5.Graphics object from the web page.
361376
* pg.remove();
377+
*
378+
* // Delete the p5.Graphics object from CPU memory.
379+
* pg = undefined;
362380
* }
363381
* </code>
364382
* </div>

0 commit comments

Comments
 (0)