Top "Singleton" questions

A design pattern that ensures that exactly one application-wide instance of a particular class exists.

Execute a method when a variable value changes in Swift

I need to execute a function when a variable value changes. I have a singleton class containing a shared variable …

ios swift properties singleton
WPF: Cannot reuse window after it has been closed

I am trying to keep one instance of a Window around and when needed call ShowDialog. This worked find in …

c# .net wpf singleton window
Thread Safe singleton class

I wrote a below Singleton class. I am not sure whether this is thread safe singleton class or not? public …

java multithreading singleton
Unit testing with singletons

I have prepared some automatic tests with the Visual Studio Team Edition testing framework. I want one of the tests …

unit-testing singleton
Is the C# static constructor thread safe?

In other words, is this Singleton implementation thread safe: public class Singleton { private static Singleton instance; private Singleton() { } static Singleton() { …

c# multithreading singleton
C++ singleton vs. global static object

A friend of mine today asked me why should he prefer use of singleton over global static object? The way …

c++ static singleton global-variables
Android: Cannot perform this operation because the connection pool has been closed

I was reading through StackOverflow about this question and I still haven't found a solution. I notice that sometimes, my …

java android database sqlite singleton
Singleton with parameters

I need a singleton class to be instantiated with some arguments. The way I'm doing it now is: class SingletonExample { …

c# design-patterns parameters singleton arguments
Global or Singleton for database connection?

What is the benefit of using singleton instead of global for database connections in PHP? I feel using singleton instead …

php design-patterns singleton
Non-Singleton Services in AngularJS

AngularJS clearly states in its documentation that Services are Singletons: AngularJS services are singletons Counterintuitively, module.factory also returns a …

service angularjs singleton instance factory