473,473 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 8111
<"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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.