Possible memory leak?

27 views
Skip to first unread message

Randy Haid

unread,
Mar 18, 2021, 5:05:31 PM3/18/21
to PDFTron SDK
I'm using the iOS SDK (8.1.2 via SPM) and, at least in the simulator, it looks like the memory continues to grow as I view documents.  I tried to strip out all my custom code, and just doing the following snippet still causes memory to grow:

        let docController = PTDocumentController()
        let navController = UINavigationController(rootViewController: docController)
        let fileURL = URL(string: downloadLink)!
        docController.openDocument(with: fileURL)
        presenter.present(navController, animated: true, completion: nil)

I'm accessing a file from AWS instead of locally.  That "presenter" variable is just one of my UIViewController classes.  The PDF opens and displays just fine, but when I leave the screen and come back to view a new document, I see the memory used is growing pretty significantly.

In my custom class, derived from PTDocumentController, I did try overriding viewWillDissapear and manually call closeDocument, which seems to help a LOT, but the memory still grows pretty quickly.

Any help would be greatly appreciated!!  Thanks.

Jamie Dassoulas

unread,
Mar 19, 2021, 3:09:31 PM3/19/21
to PDFTron SDK
Hi,

Thank you for getting in touch with us about this.
We are investigating this behaviour and we will let you know once we have more information.

Jamie Dassoulas

unread,
Mar 24, 2021, 5:41:19 PM3/24/21
to PDFTron SDK
Hi,

Thank you for reporting this.
We discovered a situation where the PTDocumentController was not being deallocated when removed from the view which seems to be the likely culprit.
This issue only occurs when running on iOS 14.
We've implemented a fix which is now available in our stable nightly builds as of 2021-03-24:

This fix will also be in our future releases.
If you prefer to wait for an official release, a workaround would be to call the following inside your PTDocumentController subclass' viewWillDisappear:

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    self.moreItemsButtonItem.menu = nil // set this property to nil
}
Reply all
Reply to author
Forward
0 new messages