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.
This commit is contained in:
parent
534b22aec5
commit
1b076b7a35
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user