WCF Memory Performance InstanceContextMode
I've been learning my way around WCF and I've got a question regarding the InstanceContextMode.
Correct me if I'm wrong, but the WCF will instantiate your object, then call the service method on it per call by default.
You can then set it to be PerSession or Single.
It seems to me that it would make more sense to have something between session and call which could reuse your object. I.e if my service were reentrant, then I could open connections to databases etc. in the constructor, then leave the object in memory to answer calls concurrently.
But in the current WCF implementation, it seems that it will always recreate the object no matter what.
The samples here
show how to use extensibility to exercise more fine-grained control over how instances are created and destroyed (e.g. pooling).
Even while using PerCall instancemode, you can still re-use heavy data structures if those are static. Remember, static objects will have the lifetime of the appdomain so lets say if you initialized a static object (which required an expensive operation), it will be visible to other WCF per call instances as well and will remain alive until the appdomain is destroyed (the lifetime of appdomain depends upon your server settings).
Be careful to handle the synchronization issues and also NOT to have any information in this static class which you DON'T want to share between all your per call instances.