From 23b7219a5d39577f752be939ee25db2484d465b6 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 10 Sep 2025 09:58:09 +0200 Subject: [PATCH] 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. --- core/display.js | 3 +++ tests/test.display.js | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/display.js b/core/display.js index ef42ac66..4efd6f4b 100644 --- a/core/display.js +++ b/core/display.js @@ -521,6 +521,9 @@ export default class Display { return; } this.drawImage(a.img, a.x, a.y); + // This helps the browser free the memory right + // away, rather than ballooning + a.img.src = ""; } else { a.img._noVNCDisplay = this; a.img.addEventListener('load', this._resumeRenderQ); diff --git a/tests/test.display.js b/tests/test.display.js index 5844ce17..528b1906 100644 --- a/tests/test.display.js +++ b/tests/test.display.js @@ -384,10 +384,11 @@ describe('Display/Canvas helper', function () { }); it('should draw an image from an image object on type "img" (if complete)', function () { + const img = { complete: true }; display.drawImage = sinon.spy(); - display._renderQPush({ type: 'img', x: 3, y: 4, img: { complete: true } }); + display._renderQPush({ type: 'img', x: 3, y: 4, img: img }); expect(display.drawImage).to.have.been.calledOnce; - expect(display.drawImage).to.have.been.calledWith({ complete: true }, 3, 4); + expect(display.drawImage).to.have.been.calledWith(img, 3, 4); }); }); });