AlessioLuciani / flutter-pdf-text

A plugin for Flutter that allows you to read the text content of PDF documents and convert it into strings.
MIT License
18 stars 45 forks source link

Memory leak in PDFDoc.text #29

Open HarvsG opened 3 years ago

HarvsG commented 3 years ago

I am using your great plugin - many thanks.

This error is not actually causing me any problems

I have noticed that when I call

_pdfDoc = await PDFDoc.fromPath(filePickerResult.files.single.path!);
String text = await _pdfDoc!.text; // <-- line that causes the error

I get an error:

I/or.myapp(19996): Background concurrent copying GC freed 306941(8MB) AllocSpace objects, 17(1916KB) LOS objects, 50% free, 14MB/28MB, paused 161us total 266.489ms
W/System  (19996): A resource failed to call end.
2 W/System  (19996): A resource failed to call close.
2 W/System  (19996): A resource failed to call end.

Unfortunately there is no stack trace and I am not experienced with the memory inspector

flutter doctor -v
[✓] Flutter (Channel stable, 2.0.4, on Linux, locale en_GB.UTF-8)
    • Flutter version 2.0.4 at /home/george/snap/flutter/common/flutter
    • Framework revision b1395592de (8 days ago), 2021-04-01 14:25:01 -0700
    • Engine revision 2dce47073a
    • Dart version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /home/george/Android/Sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /snap/android-studio/current/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = /snap/bin/chromium

[✓] Android Studio
    • Android Studio at /snap/android-studio/current/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = /snap/android-studio/current/android-studio
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (2 available)
    • TA 1033 (mobile) • PLEGAR1763000928 • android-arm64  • Android 9 (API 28)
    • Chrome (web)     • chrome           • web-javascript • Chromium
      89.0.4389.114 snap

• No issues found!

Stack overflow seems to think that enabling "strict mode" will provide a better stack trace but I am not sure how to do that in a flutter app.

Using break points I tracked the error to this line https://github.com/AlessioLuciani/flutter-pdf-text/blob/6e042e8181f71f21471516fc7740b7d298c21942/lib/pdf_text.dart#L101

and then specifically this line within the call to _invokeMethod

 codec.encodeMethodCall(MethodCall(method, arguments)),