I have code for which MemoryStream does not disposes the value.
MemoryStream ms = new MemoryStream();
string result = RandomFunction(out ms, string input) //the stream value is generated inside the Randomfunction
// Some code which uses the bytes of ms stream
ms.Close()
So even after Closing the stream. The variable ms does not dispose the value. Please suggest where I am going wrong.
Thanks in advance.
MemoryStream
class aDispose
method is emptyClose
andDispose
are synonyms, andusing
will callDispose
. So whatever symptoms you're experiencing, they are not related to the absence ofDispose
. Note that disposal and garbage collection are distinct concepts. If you're experiencing a memory leak, you need to obtain a profiler or a memory dump and trace the GC Roots that are keeping objects alive longer than you believe they should be.