Skip to content

Commit 23b7219

Browse files
committed
Drop Image data once rendered
Helps the browser to free up the memory right away, rather than waiting until some later cleanup process. At least Firefox can start consuming gigabytes of memory without this.
1 parent 8ebd9dd commit 23b7219

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

core/display.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,9 @@ export default class Display {
521521
return;
522522
}
523523
this.drawImage(a.img, a.x, a.y);
524+
// This helps the browser free the memory right
525+
// away, rather than ballooning
526+
a.img.src = "";
524527
} else {
525528
a.img._noVNCDisplay = this;
526529
a.img.addEventListener('load', this._resumeRenderQ);

tests/test.display.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,11 @@ describe('Display/Canvas helper', function () {
384384
});
385385

386386
it('should draw an image from an image object on type "img" (if complete)', function () {
387+
const img = { complete: true };
387388
display.drawImage = sinon.spy();
388-
display._renderQPush({ type: 'img', x: 3, y: 4, img: { complete: true } });
389+
display._renderQPush({ type: 'img', x: 3, y: 4, img: img });
389390
expect(display.drawImage).to.have.been.calledOnce;
390-
expect(display.drawImage).to.have.been.calledWith({ complete: true }, 3, 4);
391+
expect(display.drawImage).to.have.been.calledWith(img, 3, 4);
391392
});
392393
});
393394
});

0 commit comments

Comments
 (0)