google-developer-training/android-basics-kotlin-unscramble-app

onDetach() and onCleared() only called when TextField not empty

ILoveAngus opened this issue · 1 comments

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-training-viewmodel?hl=zh-cn&continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-3-pathway-3%3Fhl%3Dzh-cn%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-viewmodel#5

In which task and step of the codelab can this issue be found?
The lifecycle of a ViewModel

Describe the problem
onDetach() and onCleared() only called when TextField is not empty, but these two objects were created at the beginning, thus I'm wondering if I open the app and then close it instantaneously, these objects will not be recycled or there's another way?

Steps to reproduce?

  1. Go to unscramble app
  2. Close the app
  3. Open scramble app again
  4. Type some characters
  5. Close the app

Versions
Android Studio version: Android Studio Electric Eel | 2022.1.1 Patch 1
API version of the emulator: API 33

Additional information
截屏2023-02-16 下午3 07 02

I've noticed that one of the ViewModel's functionality is preventing data leakage, so if there's nothing to leak then you have nothing to recycle? How about memory expenditure?