Re: Do I need to call MemoryStream.Close ?
- From: Helge Jensen <helge.jensen@xxxxxxx>
- Date: Mon, 06 Jun 2005 19:37:14 +0200
Nicholas Paldino [.NET/C# MVP] wrote:
Also, it is good practice to always call Dispose on any instance of a type that implements IDisposable.
If you are the one "responsible" for that object. For example:
void foo(Stream s) {
s.Write(...);
// should usually *not* invoke s.Dispose();
}whereas the creator of the object should (usually) either: Dispose() it when done:
void bar() {
using ( MemoryStream s = new MemoryStream() ) {
foo(s);
...;
}
}or be sure it has given that responsibility to some other code:
class Baz: IDispoable {
Stream s;
void Dispose() { if ( s != null ) s.Dispose(); }
}
void quux(Baz baz) {
baz.s = new MemoryStream();
}-- Helge Jensen mailto:helge.jensen@xxxxxxx sip:helge.jensen@xxxxxxx -=> Sebastian cover-music: http://ungdomshus.nu <=- .
- Follow-Ups:
- Re: Do I need to call MemoryStream.Close ?
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Do I need to call MemoryStream.Close ?
- References:
- Do I need to call MemoryStream.Close ?
- From: Oleg Subachev
- Re: Do I need to call MemoryStream.Close ?
- From: Nicholas Paldino [.NET/C# MVP]
- Do I need to call MemoryStream.Close ?
- Prev by Date: Re: Please Explain where will the struct be stored if it is declared inside the Class
- Next by Date: Re: .Net (C#) Service Fails To Start
- Previous by thread: Re: Do I need to call MemoryStream.Close ?
- Next by thread: Re: Do I need to call MemoryStream.Close ?
- Index(es):
Relevant Pages
|