flutter_pdfview icon indicating copy to clipboard operation
flutter_pdfview copied to clipboard

Memory Leak

Open flbaue opened this issue 2 years ago • 5 comments

I have an app in witch I show the PDFView inside a PageView.builder. This allows the user to swipe left and right between multiple documents. After swiping lots of documents, the app gets terminated because of too much memory consumption (iOS).

The memory view from the dart dev tools shows me that all the PDFView instances are still retained by their PDFViewController.

I have added a dispose method to the _PDFViewState that calls dispose on the controller and sets the reference to null. Inside the controller I added a dispose method that sets the methodCallHandler to null, the channel to null and the widget to null.

With these changes the PDFView does not get retained and disappears from the memory.

flbaue avatar Jun 14 '23 08:06 flbaue

I can confirm I'm also getting multiple PDFView instances and I did manage to get 0 instances with your solution @flbaue. But now I'm facing a memory leak on iOS native classes: image

dfalmeida avatar Jul 28 '23 17:07 dfalmeida

@dfalmeida yes, I also noticed that and it still causes the app to crash. But I did not find a solution so far.

flbaue avatar Jul 28 '23 22:07 flbaue

@flbaue I think I've found a quick fix, not the ideal but it frees the memory. Under the file FlutterPDFView.m inside the @implementation FLTPDFView add a new method:

- (void)removeFromSuperview {
  _controler = nil;
  _pdfView = nil;
}

dfalmeida avatar Aug 01 '23 10:08 dfalmeida