bobby
04/18/2022, 4:26 AMsingle
and factory
AFAIK, single
is used to create only one instance during the application lifetime, so when there is a request about the class instance, it will receive the same one, and only disposed when the application get terminate. while factory
instance will be created new one every time there is a request with the class, but it’s not clear to me when will it dispose. moreover, there is no explanation (after some research) for the memory usage for those two
can someone please explain about the memory usage? really appreciate it
my colleague really care about the memory usage, since our app is quite large, we try to save every memory we could
thank youPedro Francisco de Sousa Neto
04/18/2022, 11:33 AMarnaud.giuliani
04/19/2022, 8:56 AMarnaud.giuliani
04/19/2022, 8:56 AMPedro Francisco de Sousa Neto
04/19/2022, 1:19 PMbobby
04/20/2022, 1:20 AMscoped and single will retain it until we ask to drop itso under the hood, for the memory management is the same, right? the difference is in the instance, factory will create a new one, while scoped and single will retain until it got dropped
bobby
04/20/2022, 1:22 AM`Single`/`factory`/`scoped` it will be disposed when you unloadKoinModule that was holding/declaring.this will be the case if you explicitly unload the module. but what if you not state it explicitly? it’s quite rare for me to do like you mentioned
arnaud.giuliani
04/20/2022, 6:54 AMPedro Francisco de Sousa Neto
04/20/2022, 12:52 PMPedro Francisco de Sousa Neto
04/20/2022, 12:55 PMPedro Francisco de Sousa Neto
04/20/2022, 12:56 PMarnaud.giuliani
04/20/2022, 1:16 PMPedro Francisco de Sousa Neto
04/20/2022, 1:43 PMfragmentScope()
extension fuction.
It’ll be necessary to load and unload module these modules in fragment?Pedro Francisco de Sousa Neto
04/20/2022, 1:45 PMarnaud.giuliani
04/20/2022, 8:47 PMarnaud.giuliani
04/20/2022, 8:47 PMarnaud.giuliani
04/20/2022, 8:48 PMfactory
instances, you will follow android lifecycle naturally. If you need more complex assembling, perhaps scopes can be usefulPedro Francisco de Sousa Neto
04/20/2022, 9:24 PMbobby
04/21/2022, 1:19 AMI agree with you @bobby. It’s not a normal case but sometimes we discover some modules in fragments that was loaded and not unloaded.this is interesting, since my team want implement single activity that recommended by Google, it’s important to not leak anything on fragment once it destroy. if i’m not wrong, leaving unload scope could become a leak in a fragment (please validate this)