packages.flutter
packages.flutter copied to clipboard
Crashes on Web after 80-100 individual page renders
Describe the bug The browser page crashes after opening a PDF and rendering a single page some 100 times.
To Reproduce This code consistently crashes between iteration 80 and 100 on my MacBook Pro for a (mixed text and image) file of 150k bytes:
Future<void> render(int times) async {
for (var i = 1; i <= times; i++) {
try {
print('Rendering $i');
final document = await PdfDocument.openData(_fileBuffer!);
final page = await document.getPage(1);
await page.render(width: page.width, height: page.height);
await page.close();
await document.close();
} catch (e) {
print('Exception on render $i: $e');
}
}
}
Expected behaviour Render infinitely without crashing :-)
Environment
- pdfx version: 2.0.1+2 on Flutter 3.0.5
- Browser: Chrome web browser
- OS: Experienced on both MacOS 12.4 and Windows 11
Additional context (none)
It looks the problem is caused by a resource leak in opening / closing the PDF document, as rendering many pages without closing and reopening the document does work.