开发者

Is a singleton shared through a different applications?

开发者 https://www.devze.com 2023-01-19 06:20 出处:网络
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 inst

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 fr开发者_运维问答om 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.


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.


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消