tags:

views:

88

answers:

4

I am wondering: if I create a singleton class with a private constructor and one static method which will return instance of this class and I put it to assembly, what will happen if I access this instance from two different applications?

Do the applications will always share the same instance of the singleton?

And if both of those applications unload from the memory the instance will be freed as well?

Thanks.

+5  A: 

Two different applications will not share the object, no. They will of course share the exact same code for the object, since they are loading the same assembly, but they will each have their own single copy, in their own address space.

In fact - even the same application, running twice, will not share the actual Singleton instance between them.

Andrew Barber
Even more specifically, static instances are not shared across AppDomain boundaries, so you can even have 2 singletons in a single running application instance.
codekaizen
+1  A: 

I don't think so, without doing nothing you will have one singleton per application space.

Pablo Castilla
+1  A: 

Not if you don't specifically make it a shared singleton by saving/loading it to the same physical location on drive or in database.

Grozz
+2  A: 

A Singleton class will be per appdomain basis so if you have more than one appdomains which loads your singleton class than more than 1 instances can be found of your singleton class.

Cross process Singleton does not have any meaning , you will have different instances

saurabh