Bitmaps larger than 495 × 495 × 4 leak in WASM
See original GitHub issueDescribe the bug
FPDF.Bitmap_Destroy()
leaks above a certain size in multiple browsers.
To Reproduce Steps to reproduce the behavior:
-
Open developer tools
-
Add 2 live expressions to watch:
wasmMemory
andwasmMemory.buffer.byteLength
(only in Chrome-like browsers) -
You can also open the browser task manager with: <kbd>Shift</kbd> + <kbd>Esc</kbd>, locate the PDF Viewer tab there and watch that
-
Evaluate the following one block at a time in the developer console (reload tab in between each block for test hygiene)
(_PDFium_Init()
is repeated for your copy+paste convenience and repeating/not-repeating it does not change the behavior.)
1. s
=
1000
; _free(_malloc(())
– evaluate in console ✔️ (no leak)
wasmMemory
wasmMemory.buffer.byteLength
_PDFium_Init(); var s = 1000; for (let i = 0; i < 100; i++) _free(_malloc(s * s * 4)); // ✔️
wasmMemory.buffer.byteLength
wasmMemory
2. s
=
100
; Destroy(CreateEx(s, s, 4)
✔️
_PDFium_Init(); var s = 100; for (let i = 0; i < 10; i++) FPDF.Bitmap_Destroy(FPDF.Bitmap_CreateEx(s, s, 4)); // ✔️
3. s
=
495
✔️
_PDFium_Init(); var s = 495; for (let i = 0; i < 10; i++) FPDF.Bitmap_Destroy(FPDF.Bitmap_CreateEx(s, s, 4)); // ✔️
4. s
>=
496
❌
_PDFium_Init(); var s = 496; for (let i = 0; i < 10; i++) FPDF.Bitmap_Destroy(FPDF.Bitmap_CreateEx(s, s, 4)); // ❌
Bindings to confirm bitmap behavior.
_PDFium_Init();
FPDF.Bitmap_GetWidth = Module.cwrap('FPDFBitmap_GetWidth', 'number', ['number']);
FPDF.Bitmap_GetHeight = Module.cwrap('FPDFBitmap_GetHeight', 'number', ['number']);
FPDF.Bitmap_GetBuffer = Module.cwrap('FPDFBitmap_GetBuffer', 'number', ['number']);
FPDF.Bitmap_Create = Module.cwrap('FPDFBitmap_Create', 'number', ['number', 'number', 'number']); // ⚠️ same issue
Expected behavior There should be no leaks at any size.
System (please complete the following information):
- OS: Windows 10 Version
20H2
(OS Build19042.1055
) - Browsers: Chrome
91.0.4472.77
; Firefox89.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:57 (17 by maintainers)
i recognize this now. It’s making sense to me.
This is all thread blocking btw. If i can get my solution working, i will contribute part of it to this repo as it removes a lot (if not all) of the thread blocking that happens in this index.html build. I have refactored a lot but its been difficult as the DOM manipulation has to be extracted to separate areas.