Configurations for Dependency Disposal
Learn to configure GetX to manage dependency disposal from memory.
Changing the default disposal behavior with SmartManagement
GetX optimizes for performance. By default, it deletes all the attached controllers once the widget is disposed of. This may be ideal for most scenarios, but sometimes, we need to preserve those controllers for later access. We mark individual controllers as permanent
during initialization to prevent them from deleting.
But what if we wish to change this default behavior and preserve all the controllers? GetX allows us to do this by providing some configuration options under SmartManagement
.
GetMaterialApp
has a smartManagement
parameter that accepts one of the three modes defined under the SmartManagement
enum. The following are the three modes:
Full mode
Keep factory mode
Only builder mode
Let us understand the function of each of these modes one by one.
Full mode
While in full mode, every controller gets completely deleted when the attached route (or widget) gets disposed of. By complete deletion, we mean that if a controller was initialized lazily, it won’t be initialized again if another widget needs it again.
Get hands-on with 1400+ tech skills courses.