Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encountering an OutOfMemoryError when loading a large PDF. #2192

Open
kishankothiya47 opened this issue Dec 2, 2024 · 1 comment
Open

Encountering an OutOfMemoryError when loading a large PDF. #2192

kishankothiya47 opened this issue Dec 2, 2024 · 1 comment
Labels
open Open pdf viewer PDF viewer component

Comments

@kishankothiya47
Copy link

Bug description

The app crashes when loading a large PDF using this package.

OutOfMemoryError
Failed to allocate a 409743384 byte allocation with 25165824 free bytes and 115MB until OOM, target footprint 441355592, growth limit 536870912

Steps to reproduce

When loading this PDF [https://inductme-uploads.s3.eu-west-2.amazonaws.com/project-media/3f94c61c-577d-451b-9838-d06f9b1a7d62-1731960193425.pdf](Sample PDF)

Code sample

Code sample
SfPdfViewer.network(
        url,

        onDocumentLoaded: (PdfDocumentLoadedDetails details) {
        },
        onDocumentLoadFailed: (PdfDocumentLoadFailedDetails details) {

         // not capturing here
          debugPrint("Error: ${details.error}");
          debugPrint("Description: ${details.description}");
        },
        onPageChanged: (PdfPageChangedDetails details) {
        },
      )

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Stack Traces

Stack Traces
Exception Logs

E/AndroidRuntime(17712): 	at java.util.Arrays.copyOf(Arrays.java:3670)
E/AndroidRuntime(17712): 	at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:120)
E/AndroidRuntime(17712): 	at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:95)
E/AndroidRuntime(17712): 	at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:156)
E/AndroidRuntime(17712): 	at io.flutter.plugin.common.StandardMessageCodec.writeBytes(StandardMessageCodec.java:196)
E/AndroidRuntime(17712): 	at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:247)
E/AndroidRuntime(17712): 	at io.flutter.plugin.common.StandardMethodCodec.encodeSuccessEnvelope(StandardMethodCodec.java:61)
E/AndroidRuntime(17712): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:272)
E/AndroidRuntime(17712): 	at com.syncfusion.flutter.pdfviewer.SyncfusionFlutterPdfViewerPlugin.getPage(SyncfusionFlutterPdfViewerPlugin.java:187)
E/AndroidRuntime(17712): 	at com.syncfusion.flutter.pdfviewer.SyncfusionFlutterPdfViewerPlugin.onMethodCall(SyncfusionFlutterPdfViewerPlugin.java:72)
E/AndroidRuntime(17712): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/AndroidRuntime(17712): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/AndroidRuntime(17712): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/AndroidRuntime(17712): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/AndroidRuntime(17712): 	at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(17712): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(17712): 	at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime(17712): 	at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime(17712): 	at android.app.ActivityThread.main(ActivityThread.java:8663)
E/AndroidRuntime(17712): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17712): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)

On which target platforms have you observed this bug?

Android

Flutter Doctor output

Doctor output
[Add your output here]
@SamAAdd
Copy link

SamAAdd commented Dec 2, 2024

Just to add to this, it seems it's due to the high resolution images which are on the PDF in question - it's less about the size of the actual PDF. We've tried with a different PDF file, same size but not images and it loads fine - the one which does not load has a number of images as detailed here: https://ibb.co/GFJKRSg

This is what chat gpt has to say about it:

  • The second PDF contains multiple high-resolution images, which significantly increase memory usage when the PDF Viewer plugin attempts to render them. The rendering process converts these images into bitmaps, which consume a large amount of memory.

  • Bitmaps in Android require uncompressed memory, often at 4 bytes per pixel for ARGB. For example, an image at 3200x3200 resolution could require over 40 MB of memory (3200 × 3200 × 4 bytes).

  • Flutter's Dart VM Memory Limit: The default memory allocation for Flutter apps may not be sufficient for rendering such resource-heavy PDFs.

@VijayakumarMariappan VijayakumarMariappan added pdf viewer PDF viewer component open Open labels Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open Open pdf viewer PDF viewer component
Projects
None yet
Development

No branches or pull requests

3 participants