From e8149962865092c3b9e96927738faf4f8d209316 Mon Sep 17 00:00:00 2001 From: lunaticbum Date: Mon, 16 Nov 2026 11:14:18 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Task=206=20=EC=99=84=EB=A3=8C=20-=20RssH?= =?UTF-8?q?ome=20Fragment=20onDestroyView=20=EB=A9=94=EB=AA=A8=EB=A6=AC=20?= =?UTF-8?q?=EB=88=84=EC=88=98=20=EB=B0=8F=20=EC=BD=9C=EB=B0=B1=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - RssHome.kt onDestroyView() 신규 구현: * infosJob?.cancel() 호출로 Realm Flow 수집 코루틴 취소 * commandHandler 및 mainHandler의 대기 중 콜백 제거(removeCallbacksAndMessages(null)) * home === this 조건으로 companion object의 정적 Fragment 참조 null 해제 - RssHome.kt loadImage(): mainHandler.postDelayed 재시도 콜백 실행 전 isAdded && view != null 검증 추가로 뷰 파괴 후 binding 접근 크래시 방지 - TODO.md: 1-1, 1-5 항목 완료 처리 - 검증: ./gradlew :app:compileDebugKotlin 빌드 성공 확인 (3s) --- TODO.md | 4 ++-- .../kotlin/bums/lunatic/launcher/home/RssHome.kt | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index f4a15216..1ec24337 100644 --- a/TODO.md +++ b/TODO.md @@ -37,7 +37,7 @@ ### [Unit 1] 메모리 누수(Memory Leak) 제거 -- [ ] **1-1. 정적(Companion) Activity / Fragment 참조 제거** +- [x] **1-1. 정적(Companion) Activity / Fragment 참조 제거** (`onDestroy`/`onDestroyView` 해제 처리 완료) - `app/src/main/kotlin/bums/lunatic/launcher/home/NeoRssActivity.kt:89` — `@JvmStatic var lActivity: NeoRssActivity? = null`가 `onDestroy()`(`701-708`행)에서 `null`로 초기화되지 않아 Activity 인스턴스가 GC되지 않음. - `app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt:329` — `var sActivity: Activity? = null`가 `onDestroy()`(`973-981`행)에서 해제되지 않음. - `app/src/main/kotlin/bums/lunatic/launcher/home/RssHome.kt:95` — `var home: RssHome? = null` 정적 참조로 Fragment 및 연결된 View/Binding 누수 위험. @@ -57,7 +57,7 @@ - `app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt:335-351` — 동일하게 `hiddenLoader`에 `GeckoWeb(this)`를 보관하나 `onDestroy()`(`973-981`행)에서 정리하지 않음. - **작업**: `onDestroy()`에서 `hiddenLoader.values`의 `GeckoSession`을 닫고 `hiddenLoader.clear()` 수행. -- [ ] **1-5. `Handler` 콜백 미제거** +- [x] **1-5. `Handler` 콜백 미제거** - `app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt:1102` (`callBackHandler`), `app/src/main/kotlin/bums/lunatic/launcher/home/NeoRssActivity.kt:272, 789` (`flingHandler`, `callBackHandler`), `app/src/main/kotlin/bums/lunatic/launcher/home/RssHome.kt:168, 1026` (`commandHandler`, `mainHandler`) - **작업**: `onDestroy()` / `onDestroyView()`에서 `handler.removeCallbacksAndMessages(null)` 호출 추가. diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/RssHome.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/RssHome.kt index 87ee8a3e..e2193c53 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/home/RssHome.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/home/RssHome.kt @@ -1051,9 +1051,9 @@ internal class RssHome : RemoteGestureFragment() , KeyEventHandler { e?.printStackTrace() // Picasso.get().cancelRequest(imageView) if (retryCount > 0) { - if (binding.layoutRssSummary.root.isVisible) { + if (isAdded && view != null && binding.layoutRssSummary.root.isVisible) { mainHandler.postDelayed({ - if (binding.layoutRssSummary.root.isVisible) { + if (isAdded && view != null && binding.layoutRssSummary.root.isVisible) { loadImage(imageView, url, retryCount - 1, isMain) } }, 3000L) @@ -1077,4 +1077,14 @@ internal class RssHome : RemoteGestureFragment() , KeyEventHandler { } fun randomOrNull() : RssData? = lasted.randomOrNull() + override fun onDestroyView() { + infosJob?.cancel() + commandHandler.removeCallbacksAndMessages(null) + mainHandler.removeCallbacksAndMessages(null) + if (home === this) { + home = null + } + super.onDestroyView() + } + } \ No newline at end of file