Vaibhav Jaiswal
11/01/2024, 4:23 PMArkadii Ivanov
11/01/2024, 4:51 PMVaibhav Jaiswal
11/02/2024, 10:42 AMVaibhav Jaiswal
11/02/2024, 10:44 AMArkadii Ivanov
11/02/2024, 10:59 AMlifecycle
artifact from Essenty, but will keep using the others like state-keeper
, instance-keeper
and back-handler
.Arkadii Ivanov
11/02/2024, 11:00 AMAlso, If I am using retained Components, are all my decompose components behaving the same as ViewModels ?Yes. You should take extra care to not leak the activity.
Vaibhav Jaiswal
11/02/2024, 11:03 AMArkadii Ivanov
11/02/2024, 11:04 AMInstanceKeeper
is similar to ViewModelStore
, InstanceKeeper.Instance
is similar to ViewModel
.
In retained mode, Components are conceptually similar to ViewModels
, but with navigation and lifecycle capabilities. You don't need InstanceKeeper
in this case, it will be just the same scope.Arkadii Ivanov
11/02/2024, 11:05 AMIn what case, can Activity get leaked?If you pass the activity context (or a dependency capturing the activity context) to a retained component via its constructor.
Arkadii Ivanov
11/02/2024, 11:06 AMclass MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val root =
retainedComponent { componentContext ->
DefaultRootComponent(
componentContext,
this@MainActivity, // <-- memory leak
)
}
}
}
Vaibhav Jaiswal
11/02/2024, 11:06 AMArkadii Ivanov
11/02/2024, 11:07 AMI do pass a dependency into my component, but that uses applicationContext, so thats okay i guessYep, this. is fine.
Vaibhav Jaiswal
11/02/2024, 11:07 AMval permissionsController = PermissionsController(applicationContext = applicationContext)
.also { it.bind(this.lifecycle, supportFragmentManager) }
val rootComponent = retainedComponent(
discardSavedState = discardSavedState
) {
RootComponentImpl(it, deeplink, permissionsController)
}
Arkadii Ivanov
11/02/2024, 11:59 PM