From 8c494f314cf77e54675f8d9742d50ed0ef94df59 Mon Sep 17 00:00:00 2001 From: Two-Ai <81279822+Two-Ai@users.noreply.github.com> Date: Fri, 13 Jan 2023 22:30:47 -0500 Subject: [PATCH] Fix DownloadPageLoader resource leak (#8905) The underlying ZipFile is leaking. To fix, store a reference to the ZipPageLoader and recycle it on recycle. --- .../tachiyomi/ui/reader/loader/DownloadPageLoader.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt index 1e02e0f30..8326c1422 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/DownloadPageLoader.kt @@ -29,6 +29,13 @@ class DownloadPageLoader( // Needed to open input streams private val context: Application by injectLazy() + private var zipPageLoader: ZipPageLoader? = null + + override fun recycle() { + super.recycle() + zipPageLoader?.recycle() + } + /** * Returns an observable containing the pages found on this downloaded chapter. */ @@ -43,7 +50,7 @@ class DownloadPageLoader( } private fun getPagesFromArchive(chapterPath: UniFile): Observable> { - val loader = ZipPageLoader(File(chapterPath.filePath!!)) + val loader = ZipPageLoader(File(chapterPath.filePath!!)).also { zipPageLoader = it } return loader.getPages() } @@ -61,6 +68,6 @@ class DownloadPageLoader( } override fun getPage(page: ReaderPage): Observable { - return Observable.just(Page.State.READY) + return zipPageLoader?.getPage(page) ?: Observable.just(Page.State.READY) } }