Using Keyword Dispose and GC

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Mehul Patel (mpatel_at_focus-technologies.com)
Date: 06/16/04


Date: 16 Jun 2004 06:17:31 -0700

Our .Net team have been pondering about using keyword.

We are using streams FileStream and BufferedStream. We use using
keyword at FileStream, and not BufferedStream which wraps FileStream.
So bunch of people said what if exception occurs buffered stream is
not closed.

My Argument is over advantages of using 'Using' keyword.

First Advantage being -- Using used for Dispose (Deterministic
Finalization) to free resources earlier, than later. Dispose and Close
do the same thing. This statement is valid, and is verified by
numerous sources (msdn,books,blogs,newsgroups).

Second Advantage being all objects in using bracket will have priority
in Gargbage collection ! - Is this statement valid?

If file stream is grabage collected, there is no need to use Using
keyword on BufferedStream -- Is this statement valid?.

Pl shed some light on this.
Thanks Very much.
Mehul.



Relevant Pages

  • Using Keyword Dispose and GC
    ... Our .Net team have been pondering about using keyword. ... We are using streams FileStream and BufferedStream. ... If file stream is grabage collected, there is no need to use Using ...
    (microsoft.public.dotnet.csharp.general)
  • Using Keyword Dispose and GC
    ... Our .Net team have been pondering about using keyword. ... We are using streams FileStream and BufferedStream. ... If file stream is grabage collected, there is no need to use Using ...
    (microsoft.public.dotnet.general)
  • Using Keyword Dispose and GC
    ... Our .Net team have been pondering about using keyword. ... We are using streams FileStream and BufferedStream. ... If file stream is grabage collected, there is no need to use Using ...
    (microsoft.public.dotnet.framework.clr)
  • Re: C# Vs VB.NET
    ... > because it was written in one language and then simply syntax-translated to ... Translation can usually be done line by line, keyword by ... > With s As Stream = ... ... Stream temp = null; ...
    (microsoft.public.dotnet.framework.clr)
  • Re: BufferedStream versus FileStream
    ... fastsest managed way that i can figure out is to use a FileStream. ... For reading a file the fastest way is still with a FileStream, ... Does BufferedStream offer any advantage over ... >>> BinaryReader and BinaryWriter offer any advantage over either FileStream ...
    (microsoft.public.dotnet.framework.performance)