<@UHAJKUSTU> are there any plans to migrate Essent...
# decompose
v
@Arkadii Ivanov are there any plans to migrate Essenty to use KMP supported Androidx.Lifecycle internally?
a
Yes! But not Essenty, as there is nothing to do there apart from deleting the current lifecycle code. Decompose should be migrated in the next major release 4.x. Follow: https://github.com/arkivanov/Essenty/issues/157 https://github.com/arkivanov/Decompose/issues/695
🚀 2
👀 1
v
Ahh, i see So Decompose will shift from Essenty to AndroidX.Lifecycle?
Also, If I am using retained Components, are all my decompose components behaving the same as ViewModels ? Are there any differences between viewModels and Decompose Components
a
Decompose will just stop using the
lifecycle
artifact from Essenty, but will keep using the others like
state-keeper
,
instance-keeper
and
back-handler
.
Also, 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.
v
In what case, can Activity get leaked?
a
> Are there any differences between viewModels and Decompose Components > In non-retained mode (the default one), Components are conceptually similar to AndroidX Fragments.
InstanceKeeper
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.
In 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.
Copy code
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val root =
            retainedComponent { componentContext ->
                DefaultRootComponent(
                    componentContext, 
                    this@MainActivity, // <-- memory leak
                )
            }
    }
}
v
Oh, understood Thanks I do pass a dependency into my component, but that uses applicationContext, so thats okay i guess
a
I do pass a dependency into my component, but that uses applicationContext, so thats okay i guess
Yep, this. is fine.
v
This is what I'm passing from the activity
Copy code
val permissionsController = PermissionsController(applicationContext = applicationContext)
    .also { it.bind(this.lifecycle, supportFragmentManager) }
val rootComponent = retainedComponent(
    discardSavedState = discardSavedState
) {
    RootComponentImpl(it, deeplink, permissionsController)
}
a
Keep in mind that the new instance of PermissionController is unused after configuration change.