Will calling close on my WCF service kill all resources or set them up for GC or should I set it to null also?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Firstly, WCF proxies are
IDisposable, so you can kind of useusing:Unfortunately, WCF also has a buggy
Dispose()implementation that regularly throws exceptions. However, here’s a really cool trick to get it to work correctly. I also blogged about this myself, but I think the first link is a lot better.So: use
IDisposableandusing, but use it with caution (in this case).Setting a field usually makes no difference. There are a few edge-cases (such as variables captured by multiple delegates, static fields, long-life objects, etc), but in general leave it alone. In particular, do not do this, as this can theoretically extend the life: