Do I really need to implement close() in BLoC? Confused about automatic disposal

Hey Flutter devs,

I have a question about BLoC and memory management that has been bothering me.

I know that BlocProvider automatically calls close() when the widget is disposed. So my question is: Do I still need to manually dispose of TextEditingControllers, FocusNodes, and Timers inside the close() method?
My confusion: If BlocProvider already calls close() automatically, why do I need to manually dispose everything? Won’t Flutter handle this?

Some people say it’s necessary to prevent memory leaks, but others say the framework handles it.
What’s the correct approach? Should I keep the manual disposal or is it redundant?
Thanks!

I would suspect the answer is yes, and the googles confirmed that. Basically, the Bloc object is holding other objects that need dispose(), but the Bloc object doesn’t know to call that for its components.

1 Like

First, TextEditingController and FocusNodes are misplaced in your BloC, they belong to your UI and not your business logic.

Beside that, whenever an object you create in your BloC has a dispose() method, it should ve called in your close() method.

Does this answer your question?