Open FeofanGreek opened 1 week ago
Could you please explain your issue in detail?
After loading any PDF file using a controller in the widget
I cannot understand the word "controller" in the sentence. At least, PdfViewerController does not have mechanism to load PDF files.
I mean PdfViewerController, but I may be wrong in describing the mechanism of its operation. I just assumed that it should be responsible for clearing memory after the user leaves the screen with the PDF file downloaded and displayed. I have attached 3 screenshots from our application to the message, as an example of showing memory consumption.
before loading
when loading
after disposing
As you can see, the increase in memory consumption of 300 megabytes was not cleared after the screen displaying the PDF was closed
I tested pdfrx with the following code and it reveals that only the first time load caches "something" on memory but repeatedly open/close the PDF page does not consume more. I think the document itself seems correctly closed (Actually, it's opened and closed everytime use some Pdfium functions).
The problem is with some resource caches by Pdfium. The possible cached resources are fonts and color profiles though I don't know the actual implementation.
import 'package:flutter/material.dart';
import 'package:pdfrx/pdfrx.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Test'),
),
body: Center(
child: TextButton(
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => const PdfPage()));
},
child: const Text('Press me!'),
)),
);
}
}
class PdfPage extends StatefulWidget {
const PdfPage({super.key});
@override
State<PdfPage> createState() => _PdfPageState();
}
class _PdfPageState extends State<PdfPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Pdf Page'),
),
body: PdfViewer.uri(
Uri.parse(
'https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf'),
),
);
}
}
It's a shame, well, let's live with it for now and hope that it will correct itself
@FeofanGreek 696527b introduces chromium/6555 and the memory consumption by the pdfium cache seems reduced. Could you please try it?
unfortunately it hasn't changed
Hello. We noticed an unpleasant feature for iOS. After loading any PDF file using a controller in the widget, the memory is not cleared when leaving the screen. We collect more then 200 MBytes of garbage I wanted to add a dispose controller or a cancel controller in dispose block of StateFullWidget, but the controller does not have such a methods..