question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bitmaps larger than 495 × 495 × 4 leak in WASM

See original GitHub issue

Describe the bug FPDF.Bitmap_Destroy() leaks above a certain size in multiple browsers.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://pdfviewer.github.io/

  2. Open developer tools

  3. Add 2 live expressions to watch: wasmMemory and wasmMemory.buffer.byteLength (only in Chrome-like browsers) image

  4. You can also open the browser task manager with: <kbd>Shift</kbd> + <kbd>Esc</kbd>, locate the PDF Viewer tab there and watch that

  5. 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 Build 19042.1055)
  • Browsers: Chrome 91.0.4472.77; Firefox 89.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:57 (17 by maintainers)

github_iconTop GitHub Comments

3reactions
quincartercommented, May 24, 2022

We do that already. See: https://github.com/paulocoutinhox/pdfium-lib/issues/71#issuecomment-1136067094 – function H.

i recognize this now. It’s making sense to me.

2reactions
quincartercommented, May 24, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changelog — Python 3.11.1 documentation
gh-95853: The new tool Tools/wasm/wasm_builder.py automates configure, compile, and test steps for building CPython on WebAssembly platforms. gh ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found