Does calling MemoryStream.Dispose() do anything ?

  • Thread starter Thread starter Moe Sisko
  • Start date Start date
M

Moe Sisko

Using dotnet 2.0,

Just wondering if anyone knows if calling Dispose() on
System.IO.MemoryStream does anything useful.
 
Moe said:
Just wondering if anyone knows if calling Dispose() on
System.IO.MemoryStream does anything useful.
Yes, it calls Stream.Dispose(), which in turn will dispose an event created
as a result of calling asynchronous methods (.BeginRead(), .BeginWrite())
if they were not all finished before the stream was finalized.

So you better call .Dispose(), or you might leak a single event handle in
very unlikely circumstances!
 
Pavel said:
Who knows, maybe it will in a future version of .NET... personally, I
still put all mine in using() anyway.

I can not imagine MemoryStream ever holding unmanaged data.

But I still agree with the conclusion: call Dispose on anything
that implements IDisposable is a good thing.

Arne
 
Jeroen said:
Yes, it calls Stream.Dispose(), which in turn will dispose an event
created as a result of calling asynchronous methods (.BeginRead(),
.BeginWrite()) if they were not all finished before the stream was
finalized.

So you better call .Dispose(), or you might leak a single event handle
in very unlikely circumstances!

It uses unmanaged resources ?

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top