0

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.

5
  • In MemoryStream class a Dispose method is empty Commented Aug 2, 2017 at 7:35
  • Why not let the Garbage Collector do its job? Commented Aug 2, 2017 at 7:37
  • As it creates an issue of memory leakage and even by using the using() statement does not disposes the value.
    – Ankur Rai
    Commented Aug 2, 2017 at 7:44
  • Read this answer and see if it helps. stackoverflow.com/questions/4195746/…
    – Wheels73
    Commented Aug 2, 2017 at 7:49
  • Close and Dispose are synonyms, and using will call Dispose. So whatever symptoms you're experiencing, they are not related to the absence of Dispose. 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. Commented Aug 2, 2017 at 7:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.