views:

493

answers:

1

Currently I have a web service (WCF) that exposes methods that are set to static.

From a strictly memory/GC perspective, what is different in how the CLR and GC handle static versus non-static objects?

+1  A: 

Static data won't be garbage-collected until the containing AppDomain is shut down; commonly this means the memory will stay allocated until the app is shut down, unless you're doing some kind of special AppDomain management. Non-static objects will be collected by the garbage collector, by the normal rules - no more references, and whenever the GC runs.

Bruce
Cool stuff. We are having some excessive memory allocation problems (over 400MB) for an application that is intended to run for weeks at a time. When we couldn't find anything else wrong we thought it might have been related to us using static objects. We will start recoding to non-static starting tomorrow. Thanks for your help!
Phillip
400MB is not very large.
John Saunders
John- I disagree when that 400MB takes the entire system down. After modifing the code for non-static we were able to get the application to peak at 18MB which is reasonable. Thanks again Bruce!
Phillip