From 0238cf134d1689d010e81bd81f837fbc650a8d8c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 10 Oct 2023 19:01:16 +0200 Subject: [PATCH] Don't store page-level data, in the API, after cleanup has run (bug 1854145) For large/complex images it's possible that the image-data arrives in the API *after* the page has been scrolled out-of-view and thus been cleaned-up. In this case we obviously shouldn't cache such page-level data, since it'll first of all be unused and secondly can increase memory usage *a lot*. Also, ensure that we *immediately* release any `ImageBitmap` data in this case to help reclaim memory faster. --- src/display/api.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/display/api.js b/src/display/api.js index e5ed6addb..e3f693e54 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -2768,6 +2768,11 @@ class WorkerTransport { if (pageProxy.objs.has(id)) { return; } + // Don't store data *after* cleanup has successfully run, see bug 1854145. + if (pageProxy._intentStates.size === 0) { + imageData?.bitmap?.close(); // Release any `ImageBitmap` data. + return; + } switch (type) { case "Image":