Git Product home page Git Product logo

Comments (5)

escamoteur avatar escamoteur commented on August 25, 2024

Can you explain to me how a lazy singleton would help you in this aspect?
I'm pretty sure there are better ways to achieve the same?
Did you have a closer look at get_it scopes?

from get_it.

feinstein avatar feinstein commented on August 25, 2024

If we declare Singletons they will be create as soon as they are declared and will live in memory. Scopes allow us to reduce their footprint, but then we have to be controlling scopes all over the app. I don't want to use scopes for several reasons:

1 - I have a Storage class that's used in many screens and flows in my app, but not in all of them. The ones who use it, I want them to have the same Singleton with the same internal cache. It's acceptable if it's created once by one screen and it lives there in memory, the problem is when all the singletons are created at startup and bloat the memory. If I use scopes, I will have to be micro-managing the scopes across the entire app, and I would also like to share singletons across scopes.

Let's say I have pages A, B, C, D and E. I want the same Storage on pages A, B and C, but not on D and E. Those pages are in a bottom navigator, so they are not related to each other.

2 - The less coupling my app has on third party libraries, the better. No offense, get_it is very useful, but I rather "contain" how much it influences my app in case I need to replace it one day. I declare the dependencies when the app starts and I make all the singletons and factories call each other. then I create the objects I want on a given page. This way I only have get_it in 2 places: App Initialization and Pages initialization.

from get_it.

escamoteur avatar escamoteur commented on August 25, 2024

from get_it.

feinstein avatar feinstein commented on August 25, 2024

unless they cache images or other huge Data blocks.

So you agree with me that are cases where Singletons can bloat your app's memory, so why not make the lib ready to provide to us the tools to control the memory in any way we want?

from get_it.

escamoteur avatar escamoteur commented on August 25, 2024

See our other discussion

from get_it.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.