Skip to content

Commit

Permalink
Merge pull request #7060 from iambiancafonseca/fixGraphicsRemove
Browse files Browse the repository at this point in the history
Fix #7049: P5.Graphics.remove() doesn't release all related resources
  • Loading branch information
davepagurek authored May 22, 2024
2 parents 659b0bd + 80ac8b9 commit 61f050b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/p5.Graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
* }
* </code>
Expand All @@ -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;
}


Expand Down
10 changes: 10 additions & 0 deletions test/unit/core/p5.Graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 61f050b

Please sign in to comment.