Skip to content

Commit 61f050b

Browse files
authored
Merge pull request #7060 from iambiancafonseca/fixGraphicsRemove
Fix #7049: P5.Graphics.remove() doesn't release all related resources
2 parents 659b0bd + 80ac8b9 commit 61f050b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/core/p5.Graphics.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ p5.Graphics = class extends p5.Element {
374374
* function doubleClicked() {
375375
* // Remove the p5.Graphics object from the web page.
376376
* pg.remove();
377-
*
378-
* // Delete the p5.Graphics object from CPU memory.
379377
* pg = undefined;
380378
* }
381379
* </code>
@@ -392,6 +390,10 @@ p5.Graphics = class extends p5.Element {
392390
for (const elt_ev in this._events) {
393391
this.elt.removeEventListener(elt_ev, this._events[elt_ev]);
394392
}
393+
394+
this._renderer = undefined;
395+
this.canvas = undefined;
396+
this.elt = undefined;
395397
}
396398

397399

test/unit/core/p5.Graphics.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,14 @@ suite('Graphics', function() {
184184
assert(graph.height, 100);
185185
});
186186
});
187+
188+
suite('p5.Graphics.remove()', function() {
189+
test('it sets properties to undefined after removal', function() {
190+
var graph = myp5.createGraphics(10, 17);
191+
graph.remove();
192+
assert.isUndefined(graph.canvas);
193+
assert.isUndefined(graph._renderer);
194+
assert.isUndefined(graph.elt);
195+
});
196+
});
187197
});

0 commit comments

Comments
 (0)