Home > database >  Difference between lazySingleton and singleton in Get_it
Difference between lazySingleton and singleton in Get_it

Time:11-17

Currently, I am using get_it package for dependency injection. However, I have confused about singleton and lazySingleton.

I know its difference is lazySingleton will not init until it's used and reduce init time as well as saving resource. However, I don't know what is drawbacks of lazySinglton with singleton are. Why not replace all singleton with lazySingleton.

CodePudding user response:

Both are Singletons. But LazySingleton refers to a class whose resource will not be initialised until it's used for the 1st time. It's generally used to save resources and memory.

Now the drawback, LazySingleton will take time when it is used for the first time. the other singleton may have been initialized in advance and the time taken to initialize might have been used to make the process faster.

  • Related