From 1b076b7a359e10c8b2fd38cdf00f088767ad12ba Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 21 Feb 2023 12:00:45 +0100 Subject: [PATCH] Move the `ImageBitmap` clean-up into the `PDFObjects` class With upcoming changes we'll potentially start to cache `ImageBitmap` data at the document-level, in addition to just at the page-level. Hence we need to ensure that such data is actually released on clean-up, and rather than duplicating the existing *manual* handling this code is instead moved into the `PDFObjects.clear` method. (In my opinion, this is an overall improvement even without globally cached `ImageBitmap` data.) *Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it's correct and makes sense. --- src/display/api.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index c4954f237..e578f15fc 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1282,8 +1282,6 @@ class PDFPageProxy { this.commonObjs = transport.commonObjs; this.objs = new PDFObjects(); - this._bitmaps = new Set(); - this.cleanupAfterRender = false; this.pendingCleanup = false; this._intentStates = new Map(); @@ -1679,10 +1677,6 @@ class PDFPageProxy { } } this.objs.clear(); - for (const bitmap of this._bitmaps) { - bitmap.close(); - } - this._bitmaps.clear(); this.pendingCleanup = false; return Promise.all(waitOn); } @@ -1718,10 +1712,6 @@ class PDFPageProxy { if (resetStats && this._stats) { this._stats = new StatTimer(); } - for (const bitmap of this._bitmaps) { - bitmap.close(); - } - this._bitmaps.clear(); this.pendingCleanup = false; return true; } @@ -2774,9 +2764,8 @@ class WorkerTransport { if (imageData) { let length; if (imageData.bitmap) { - const { bitmap, width, height } = imageData; + const { width, height } = imageData; length = width * height * 4; - pageProxy._bitmaps.add(bitmap); } else { length = imageData.data?.length || 0; } @@ -3150,6 +3139,10 @@ class PDFObjects { } clear() { + for (const objId in this.#objs) { + const { data } = this.#objs[objId]; + data?.bitmap?.close(); // Release any `ImageBitmap` data. + } this.#objs = Object.create(null); } }