Possible Duplicate:
Setting Objects to Null/Nothing after use in .NET
Do you need to dispose of objects and set them to null?
For large, or high traffic website:
First question:
Will set Object=null (not Disposable ) release memory?
Or is other way to release memory?
Second question:
Is explicitly release memory as above necessary in normal code?
No, it won’t do it immediately, and no, it’s usually unnecessary if you’re writing your code the right way.
If you have a resource that implements
IDisposable, callDispose()on it, or even better, put it in ausing(...)block – it’s much faster and will release the proper resources. If you have several large objects in the same scope that aren’t COM objects or don’t implement some form of disposal mechanism, doing:might help, but you’re probably better off restructuring your code so you don’t end up in that situation.
If you’re doing this before objects go out of scope, it’s completely superfluous and makes things worse. More so if you set things to
nullin your finalizer. For example, never do this:nor this:
And, for the sake of completeness, you do this:
to release a COM object.