Search code examples
c#.netvisual-studio-2008memorystream

.Net MemoryStream close issue


For a .Net MemoryStream object instance, do I need to close it explicitly after using it? Or no need to close it? Which is the best practices?

I am using VSTS2008 + .Net 3.5 + C#.


Solution

  • you should close it when you are done with it. The best practice is to close the stream in the finally section of a try-catch-finally block. you can get more information here:

    http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx