473,231 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 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 8092
<"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BH | last post by:
I'm trying a simple object serialization and deserialization, and keep getting this error: System.Runtime.Serialization.SerializationException: Binary stream does not contain a valid...
5
by: Barry Anderberg | last post by:
I'm using a tool by Sci-Tech called the .NET Memory Profiler. We have a massive .NET/C# application here and it has been exhibiting memory leak behavior for some time. Attempting to remedy the...
1
by: Greg Patrick | last post by:
My problem: I load an some assemblies (strong named) from a byte array using Assembly.Load(byte). They load fine. But one one of them is actually accessed, it's referenced assemblies can't be...
0
by: Mike Collins | last post by:
I apologize for using this newsgroup for what seems like a VB6 question, but I did not see a newsgroup for VB6. I also think I may not have the C# code setup correctly for calling from VB6. If...
9
by: Oleg Subachev | last post by:
I use local to methods MemoryStreams. Both read-only and read-write ones. Do I need to call MemoryStream.Close for read-only MemoryStreams before leaving the method ? And what about...
3
by: Ken | last post by:
How can I have my WinForm return something to the caller so it knows which button is clicked? The following is calling a system message box, just want to do the samething with my own winform....
51
by: Tony Sinclair | last post by:
I'm just learning C#. I'm writing a program (using Visual C# 2005 on WinXP) to combine several files into one (HKSplit is a popular freeware program that does this, but it requires all input and...
71
by: active | last post by:
In the main program I check to see if a certain form has been disposed. Does it make sense in that form's FormClosed event to do: Me.Dispose to make sure it is disposed the next time I check. Or...
2
by: Claire | last post by:
Hi I have a function that sends email messages plus attachments. I'm worried about the memorystream I'm using in the following clipped code sample. Will it be closed/disposed of without me doing...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.