mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 01:35:43 +02:00
Ensure that blob:
URLs will be revoked when pages are cleaned-up/destroyed
Natively supported JPEG images are sent as-is, using a `blob:` or possibly a `data` URL, to the main-thread for loading/decoding. However there's currently no attempt at releasing these resources, which are held alive by `blob:` URLs, which seems unfortunately given that images can be arbitrarily large. As mentioned in https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL the lifetime of these URLs are tied to the document, hence they are not being removed when a page is cleaned-up/destroyed (e.g. when being removed from the `PDFPageViewBuffer` in the viewer). This is easy to test with the help of `about:memory` (in Firefox), which clearly shows the number of `blob:` URLs becomming arbitrarily large *without* this patch. With this patch however the `blob:` URLs are immediately release upon clean-up as expected, and the memory consumption should thus be considerably reduced for long documents with (simple) JPEG images.
This commit is contained in:
parent
80135378ca
commit
983b25f863
2 changed files with 30 additions and 2 deletions
|
@ -480,6 +480,16 @@ function deprecated(details) {
|
|||
console.log('Deprecated API usage: ' + details);
|
||||
}
|
||||
|
||||
function releaseImageResources(img) {
|
||||
assert(img instanceof Image, 'Invalid `img` parameter.');
|
||||
|
||||
const url = img.src;
|
||||
if (typeof url === 'string' && url.startsWith('blob:') &&
|
||||
URL.revokeObjectURL) {
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
PageViewport,
|
||||
RenderingCancelledException,
|
||||
|
@ -496,4 +506,5 @@ export {
|
|||
isValidFetchUrl,
|
||||
loadScript,
|
||||
deprecated,
|
||||
releaseImageResources,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue