fix(PdfPageView): dispose the previous image before replacing it - #698
Merged
espresso3389 merged 1 commit intoAug 24, 2026
Merged
Conversation
_updateImage() replaced _image with the newly rendered image without disposing the old one first. _clearCache() disposes _image, but that method only runs from dispose()/didUpdateWidget(), never from this re-render path, so every re-render (e.g. a size/zoom change) orphaned a full-resolution dart:ui.Image. Also add a mounted guard: if the State was disposed while awaiting createImage(), _clearCache() already ran and nulled _image, so assigning newImage afterwards would leak it into a dead State with nothing left to dispose it. PdfViewer already does both of these correctly; this brings PdfPageView in line with it. Refs espresso3389#110
This was referenced Aug 24, 2026
Owner
|
This fix has been released in pdfrx 2.4.8. Written by Codex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #697.
_PdfPageViewState._updateImageoverwrites_imagewithout disposing the previous one, so every re-render that changes the requested page size (a zoom tier change, a layout change, apageSizeCallbackreturning a new size) orphans a full-resolution decodedui.Image. The only_image?.dispose()in the class is in_clearCache(), which this path never calls.It also lacked a
mountedguard on the assignment — the existing check only guardedsetState. If the widget was disposed during theawait,_clearCache()had already run and nulled_image, and the assignment then wrote a fresh image into a deadStatewhere nothing would ever dispose it.This is the second half of #110, which was closed as fixed in 1.0.51; only the
dispose()half landed.The fix matches what
PdfVieweralready does inpdf_viewer.dart(lines 1760-1764 and 1847-1852): guard on!mounted, dispose the old image, then swap.Kept deliberately minimal — no reformatting, no changelog entry (happy to add one if you'd like). I could not run
dart analyzeagainst the workspace locally: dependency resolution fails onmeta(pdfium_flutterwants 1.17.0 via the Flutter SDK'sflutter_test,pdfrx_enginewants ^1.18.0). That failure reproduces identically on unmodifiedmaster, so it is unrelated to this change.