[SOLVED] Shared server memory



I have an application where I created a class using the singleton pattern to manage access to a tab control.  Anyhow, if i open up two browser and point them to the application, I will get two independent session id(s).  However, the “singleton” class appears to be shared between the session instances.  I would have thought the server side would keep all memory/code independent between sessions, but that doesn’t appear to be the case.  I should be able to fix this on my own but was hoping you could provide a bit of explanation.



  • You must to post comments
Best Answer

Web sessions don’t really exist in .NET (or Java, php, etc). A session is simply an instance of an object saved in a global cache and identified by a key, the session id. A static (which is a singleton, or a shared in VB.NET) is always a static and it’s only 1 (.NET isolates them by AppDomain – in IIS an AppDomain is a site within an App Pool which is a process). It’s the same in ASP.NET/MVC, and in JSP, PHP, …

Typically to convert local code that uses shared singletons (statics) for a user to a web based app you have to change the storage to a session variable:

Application.Session.myShared = "Test"; // this is possible because of Wisej dynamic objects.


Application.Session["myShared"] = "Test";

However, there are also cases where you want to share an instance among all users (sessions). In these cases you can use statics (which are singletons or shared in VB.NET). For example, you can share lookup data, data sets, configuration values, and anything else that makes sense for the app at hand.




  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.