Skip to content

Memory leak when opening PDF as a byte array #84

Open

Description

@ViktorSkabiak

The library contains a memory leak when you open a PDF as a byte array.
I check the method nativeOpenMemDocument and found some weird memory copying code.
I've commented this code and memory leak has gone
image

TL;DR
I was running a 3 minutes autotest which opens the 50-pages PDF every 10 seconds.
This is the memory profiler results before the code commenting:
Screenshot 2022-05-16 at 06 23 49
and you can clearly see that native memory grows and GC cannot clear it

This is the memory profiler results after the code commenting:
Screenshot 2022-05-16 at 06 29 52
Now there is not such native memory issues. It stays relatively small and GC easily clears it

The issue was happening when I was calling the method PdfDocument newDocument(byte[] data, String password)

Activity

  1. ViktorSkabiak commented on May 16, 2022

    @ViktorSkabiak
    Author

    @barteksc Please share your thoughts on this issue? Please let me know whether it's fine that I've just commented these lines? Or is there some purpose for such memory copying?
    Glad to hear your comments.
    Thanks

  2. ViktorSkabiak commented on May 16, 2022

    @ViktorSkabiak
    Author

    UPDATE.
    After several tests I made a conclusion that the approach describe above is not acceptable.
    It works in some scenarios but also crashes in others (I cannot describe the details here because of the NDA)

    After some research, I created a new code version that works in all the scenarios.
    These are the changes that I made:
    image
    image

    The whole code is here:
    mainJNILib.txt

    @barteksc Glad to hear your opinion
    Thanks

  3. AhmerAfzal1 commented on May 18, 2022

    @AhmerAfzal1

    @ViktorSkabiak You should create a pull request to fix this issue.

  4. ViktorSkabiak commented on May 18, 2022

    @ViktorSkabiak
    Author

    @AhmerAfzal1 Should I also include in the pull request the other changes required for the NDK to be able to build it with the latest Android Studio version?
    Such changes are:

    1. APP_PLATFORM = android-19 // modern NDK doesn't support the android-14 which is currently specified in the code
    2. removed mips and mips64 support // the same reason as above
  5. AhmerAfzal1 commented on May 19, 2022

    @AhmerAfzal1

    @AhmerAfzal1 Should I also include in the pull request the other changes required for the NDK to be able to build it with the latest Android Studio version? Such changes are:

    1. APP_PLATFORM = android-19 // modern NDK doesn't support the android-14 which is currently specified in the code
    2. removed mips and mips64 support // the same reason as above

    It's best to create a pull request that includes your latest change to this repo. Make it easy for authors and other users to see the new changing and fixed bugs, always make a pull request in which you participate improves this great library.

  6. added a commit that references this issue on Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions