By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,448 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,448 IT Pros & Developers. It's quick & easy.

Does calling MemoryStream.Dispose() do anything ?

P: n/a
Using dotnet 2.0,

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


Jul 11 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
<"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.