fix: Task 6 완료 - RssHome Fragment onDestroyView 메모리 누수 및 콜백 정리

- 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)
This commit is contained in:
2026-11-16 11:14:18 +09:00
parent 9213e1210b
commit e814996286
2 changed files with 14 additions and 4 deletions
+2 -2
View File
@@ -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)` 호출 추가.
@@ -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()
}
}