Log in



Archive for September, 2009

SingleCall activation and static variables

September 24th, 2009 by Peter

In my middleware course, I asked the question of how to realize a statefulSingleCall remoting server. I expected to hear something about external state storage, e.g. in a database. To my surprise, most students proposed to use a static variable in the server implementation for keeping the state between calls.

This idea results from a pure programming-language thinking, and (for most students) from successful experimentation. Looking under the hood, it is not completely obvious that this will work in all cases. Static variables are managed by the CLR as entities bounded to a loaded class, in this case the server class. According to most sources, static variables are only garbage collected when the class is garbage collected. This can only happen if the surrounding application domain is unloaded. For a standard remoting server, this is very unlikely to happen ever.

Things become more interesting with a different runtime host than the operating system. If you use IIS, it could decide to unload your whole server application if it is not triggered often enough, or if memory is whole.

All in all, relying on static variables in a virtual runtime environment is bad style.

BTW: I know that .NET Remoting is deprecated in favour of WCF, but it is still a very helpful teaching tool.

.NET Sources

September 24th, 2009 by Peter

I was completely unaware of this, but since Visual Studio 2008, you can debug into the .NET class library sources. Shawn Burke has a good explanation how it works.

  • You are currently browsing the troeger.eu blog archives for September, 2009.