I need some reassurance that I am not creating new objects without disposing of them, or need to know how I can manually monitor and dispose of them. I thought Navigator.pop()
should dispose of my resources such as flutter-bloc cubits/blocs but it doesn't seem like it does.
I provide a cubit for a named route by using onGenerateRoute like so:
in onGenerateRoute:
case Routes.LOGGED_OUT_NICKNAME:
page = MyCustomRouteTransitionAnimation<LoggedOutNickNameView>(
builder: (context) => BlocProvider.value(
value: LoggedOutNickNameCubit(
SaveNickNameLocallyUseCase(), GetUserFieldFromLocalUseCase()),
child: LoggedOutNickNameView()),
);
break;
I have noticed that when I navigate to the route, it creates the cubit each time, which is great, but when I Navigator.pop()
, the cubit does not get closed.
When I monitor the memory in dart devtools, it seems to always show 2 instances of my cubit no matter what, so seems kind of useless. Am I reading that wrong?:
How can I get the actual number of instances of objects in memory from dart devtools, and how can I ensure I am clearing resources appropriately, especially blocs/cubits?