Anthony,
See inline:
Anthony leong kar keong said:
Hi i would like to ensure some code cleaning methods.
#1 COM objects
Is the following the correct way ?
objMe = null;
If you are using a COM object represented in .NET, then you should be
calling the static ReleaseComObject on the Marshal class, passing in the
object. Then, you should set the reference to null. In general, in .NET,
setting the reference to null will make the object eligible for garbage
collection. When that GC happens is up to you, but the sooner you release
it, the sooner it is eligible. However, unmanaged resources that are held
onto by the object are not freed. In order to do that, for this case, you
should call the ReleaseComObject method.
#2 Dispose VS. null
Mydataset.dispose();
or
Mydatatset =null
Dispose and null are not competing methods. Dispose is the way of
indicating that resources the object represents/holds should be disposed of
in a timely manner, instead of waiting for a GC. So, what you should do is
call Dispose on the object, and then set the reference to null.
#3 c# class objects
myobject Myinstance = new myobject();
...
..
Myinstance =null <--correct ?
If you are done with it, then yes. However, if it implements
IDisposable, then you might want to call Dispose on that as well.
Hope this helps.
i