Will calling close () on my WCF service release all resources?

Will the closure call of my WCF service kill all resources or configure them for the GC, or should I also set it to null?

+4
source share
3 answers

First, the WCF proxy is IDisposable , so you can use using :

 using(var proxy = new MyProxy()) { // see below - not quite enough // use proxy } 

Unfortunately , WCF also has a buggy Dispose() function that regularly throws exceptions. However, here is a really cool trick to make it work correctly. I also wrote about this, but I think the first link is much better.

So: use IDisposable and using , but use it with caution (in this case).

Setting the field usually does not matter. There are several edge cases (such as variables captured by several delegates, static fields, objects with a long lifetime, etc.), but in general leave it alone. In particular, do not do this, as this could theoretically extend life:

 if(field != null) field = null; // BAD 
+5
source

You only need to set the variable to null if it will be available over time. Say a field on a long-lived object or a static field. This is generally not just for WCF.

0
source

All Articles