diff --git a/src/core/p5.Graphics.js b/src/core/p5.Graphics.js index 81b6c3a795..07ddb54301 100644 --- a/src/core/p5.Graphics.js +++ b/src/core/p5.Graphics.js @@ -374,8 +374,6 @@ p5.Graphics = class extends p5.Element { * function doubleClicked() { * // Remove the p5.Graphics object from the web page. * pg.remove(); - * - * // Delete the p5.Graphics object from CPU memory. * pg = undefined; * } * @@ -392,6 +390,10 @@ p5.Graphics = class extends p5.Element { for (const elt_ev in this._events) { this.elt.removeEventListener(elt_ev, this._events[elt_ev]); } + + this._renderer = undefined; + this.canvas = undefined; + this.elt = undefined; } diff --git a/test/unit/core/p5.Graphics.js b/test/unit/core/p5.Graphics.js index 634f24e4c7..216f4e9d26 100644 --- a/test/unit/core/p5.Graphics.js +++ b/test/unit/core/p5.Graphics.js @@ -184,4 +184,14 @@ suite('Graphics', function() { assert(graph.height, 100); }); }); + + suite('p5.Graphics.remove()', function() { + test('it sets properties to undefined after removal', function() { + var graph = myp5.createGraphics(10, 17); + graph.remove(); + assert.isUndefined(graph.canvas); + assert.isUndefined(graph._renderer); + assert.isUndefined(graph.elt); + }); + }); });