Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diff between get.put and get.lazyput

I am new to Getx's dependency injection, so can some one explain to me the benefits of Get.put() and Get.lazyPut() and tell me also what difference they have?

like image 522
saif rehman Avatar asked Dec 05 '25 06:12

saif rehman


2 Answers

Short answer

  • Get.put() will put Immediately
  • Get.lazyPut() will put When you need it
like image 72
Tuan Avatar answered Dec 07 '25 23:12

Tuan


To my understanding put already puts an instance of the class directly in memory while lazyPut just puts a builder for it in it.

A benefit of lazyPut is that it saves memory until you actually find it. And you can also put more complex code in the builder for it. Another benefit of lazyPut is that you can also say fenix: true on it which means it's able to be reconstructed in case it got disposed of before.

I would think the only benefit of using put is that find should be slightly faster then when called because it doesn't need to call a builder first to get the instance. I don't know if there are other benefits.

like image 40
Ivo Beckers Avatar answered Dec 07 '25 23:12

Ivo Beckers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!