Home > database >  Flutter: Why do we need to dispose ViewModels?
Flutter: Why do we need to dispose ViewModels?

Time:11-09

Can someone give a simple case where we will immidiately appreciate the importance of disposing viewmodels and at the same time know the repercussions if we don't? My App is running fine without all these disposing stuff, I really just don't understand the vague "prevent memory leak" stuff.

CodePudding user response:

Disposing the resources is important when flutter says this to do because if these resources are not disposed they will remain alive and keep consuming system resources like memory, processor etc and may produce unwanted result or Null/Memory Exceptions, also it can slow down (JANK) your APP as Flutter main thread is a single thread.

Resources Like Timer if you do not cancel the time it will remain active.

CodePudding user response:

Your devices have a certain number of resources. Not disposing objects leaves them in memory, in the worst case "out of memory" errors occur. Therefore you should always take care to avoid memory leaks.

Among them e.g. timers, animations, controllers, etc.

  • Related