What are the memory management differences between Get.put(SomeClass(), permanent: true) and Get.put(SomeGetXService())
The first option always keeps the class in memory throughout the entire app's lifespan, while the second option binds the service to the stack navigation lifecycle. According to GetX dpcumentation, a GetXService is only deleted with a call to Get.reset()
. In most cases though, both methods will probably be equally valid, since in essence, a service is kept in memory throughout the entire app lifecycle anyways.
Admin
Updated on January 04, 2023Comments
-
Admin over 1 year
I am using Getx and its dependency injection mechanism.
sometime I am overthinking - should I inject a class that should remain in memory (for good as a Singelton) using
Get.put(SomeClass(), permanent: true)
or using
Get.put(SomeGetXService())
by reading the documentation, both ways seems to put the class in memory as Singelton, and it can only be deleted explicitly (i.e. not with Get.smartManagement).
as for me, I prefer not to extend the class with GetxService, since the first option is simpler to implement - but I feel like I might be missing something. having the class in memory as Singelton through out the app life-span is a must. Thanks for your help
-
vigdora almost 2 yearsso basically Get.put(SomeGetxController(), permanent: true) and Get.put(SomeGetXService()) are quite equal since both are binded to the navigation lifecycle. the only difference is the way to delete them: i.e. Get.reset() vs Get.delete(), correct me if I am wrong...
-
MrMikimn almost 2 years
permanent
binds the object to the application lifecycle. Services are bound to the navigation stack. For most purposes, this is the same thing. However, if your application continues to run in the background, thenpermanent
objects might not be cleared, but that is usually not the case for Flutter apps -
vigdora almost 2 yearsin my comment above yours I actually extended my question to GetxServices vs GetxController() , and not just simple object (as in my original question).[1] I think controllers are also binded to the navigation stack don't they? [2] so if the app is running in the background, services might be cleared? [3] why it is usually not the case for flutter apps?