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.
This commit is contained in:
Pierre Ossman
2025-09-10 09:58:09 +02:00
parent 8ebd9ddef9
commit 23b7219a5d
2 changed files with 6 additions and 2 deletions

View File

@@ -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);

View File

@@ -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);
});
});
});