If your application has a singleton that takes 200MB of memory and takes a minute to load (dont ask why :-) ), but is only needed if you use a specific part of the app, why load it on the app load?
On Friday, March 15, 2013 3:29:03 AM UTC+2, Lew wrote: > > Kristopher Micinski wrote: > >> I guess the bigger problem that in Android static data members cannot >> be statically checked to be "alive". By this I mean: you should try >> to get as much static checking as possible, and if you're using >> statics you don't have any ability to properly check this. >> >> Moreover, in Android it's a fact of life that your app will die and >> restart. You can really only use statics for "caching" type purposes, >> but working with them in a safe way quickly becomes extremely >> complicated. Instead of doing this, you can typically replace >> singletons with some Android specific utility (a Service or >> ContentProvider, say..) that allows you to implement the "singleton" >> type pattern. >> >> This really *is* a pretty frequent problem when people get UI elements >> stuck into static variables and then users rotate the screen :-) >> >> Kris >> >> On Thu, Mar 14, 2013 at 7:11 PM, Mark Murphy <[email protected]> >> wrote: >> > On Thu, Mar 14, 2013 at 7:00 PM, user123 <[email protected]> wrote: >> >> What is the problem with singleton? >> > >> > >> http://stackoverflow.com/questions/7026507/why-are-static-variables-considered-evil >> >> > >> http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons >> > >> > And, since they don't seem to emphasize the point quite enough for my >> > taste: static data members are, by definition, memory leaks. How *bad* >> > of a memory leak they are depends on what they are and how they are >> > used. >> > >> > Like many programming techniques, singletons can be used as a scalpel >> > or a sledgehammer. The general advice against singletons is because >> > most people reading that advice are inexperienced and are likely to do >> > damage with either a scalpel or a sledgehammer. >> > >> > On the whole, AFAICT, tolerance for singletons decreases with >> > increased production Java development experience, based on the >> > conversations that I have had on the topic over the past few years. >> >> > I've been using Java professionally for fourteen years. > > The biggest problem I have with singletons is that everyone for some > god-awful reason > insists on lazily instantiating them. Why? > > Lazy instantiation is lazy. What's wrong with non-lazy instantiation? Then > you can use > a 'final' reference to the singleton instance that exists without effort > or overhead. > > -- > Lew > > -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

