On Sun, 01 Jun 2008 00:18:51 -0700, tshad <ts***@dslextreme.comwrote:
So the object "fInfo" in
using (FileInfo fInfo = new FileInfo(fromImagePath + "\\" +
(string)dr["originalFileName"]))
is just an object and will be disposed of by the garbage collector after
the
method is exited or goes out of scope?
It will be collected (I prefer that term over "disposed" since the latter
has a specific meaning in .NET) according to the standard garbage
collector rule: when it is no longer reachable.
Depending on how you use the instance, this may well be when the variable
goes out of scope (exiting scope within the method, or the method itself,
for example).
Also keep in mind that it's not just FileInfo that's being collected. It
may contain other things that are also unreachable when the FileInfo
instance becomes unreachable and those will be collected as well. That's
just how the garbage collection works. The beauty of it is that you don't
need to worry about it.
The "dispose" paradigm exists in .NET primarily because of unmanaged
resources, and if an object doesn't implement IDisposable, then you don't
need to dispose it (and can't :) ).
Pete