471,348 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Does calling MemoryStream.Dispose() do anything ?

Using dotnet 2.0,

Just wondering if anyone knows if calling Dispose() on
System.IO.MemoryStream does anything useful.


Jul 11 '08 #1
8 7920
<"Moe Sisko" <null>wrote:
Using dotnet 2.0,

Just wondering if anyone knows if calling Dispose() on
System.IO.MemoryStream does anything useful.
Nope.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jul 11 '08 #2
On Jul 11, 9:36*am, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
*<"Moe Sisko" <null>wrote:
Using dotnet 2.0,
Just wondering if anyone knows if calling Dispose() on
System.IO.MemoryStream does anything useful.

Nope.
Who knows, maybe it will in a future version of .NET... personally, I
still put all mine in using() anyway.
Jul 11 '08 #3
Moe Sisko wrote:
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!

--
J.
Jul 11 '08 #4
Pavel Minaev wrote:
On Jul 11, 9:36 am, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
> <"Moe Sisko" <null>wrote:
>>Using dotnet 2.0,
Just wondering if anyone knows if calling Dispose() on
System.IO.MemoryStream does anything useful.
Nope.

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
Jul 14 '08 #5
Jeroen Mostert wrote:
Moe Sisko wrote:
>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!
It uses unmanaged resources ?

Arne
Jul 14 '08 #6
Arne Vajhøj wrote:
Jeroen Mostert wrote:
>Moe Sisko wrote:
>>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!

It uses unmanaged resources ?
Indirectly, yes. But only in the circumstances described above.

--
J.
Jul 14 '08 #7
Arne Vajhøj wrote:
Jeroen Mostert wrote:
>Moe Sisko wrote:
>>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!

It uses unmanaged resources ?
Indirectly, yes. But only in the circumstances described above.

--
J.
Jul 14 '08 #8
Arne Vajhøj wrote:
Jeroen Mostert wrote:
>Moe Sisko wrote:
>>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!

It uses unmanaged resources ?
Indirectly, yes. But only in the circumstances described above.

--
J.
Jul 14 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Barry Anderberg | last post: by
reply views Thread by Mike Collins | last post: by
9 posts views Thread by Oleg Subachev | last post: by
3 posts views Thread by Ken | last post: by
51 posts views Thread by Tony Sinclair | last post: by
2 posts views Thread by Claire | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.