0

I'm facing memory consumption issue while reading a stream to a byte array and saving the same byte array to a stream. Even after the disposal, memory gets holds up, it shows in task manager around 150MB (using WinRT). I'm looking for a good solution. Please look through the code as well.

 Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly;
 Stream stream = assembly.GetManifestResourceStream("MemryHoldUp.Assets.Correct.pdf");


 //Copy stream to byte array
 stream.Position = 0;
 long length = stream.Length;
 byte[] data = new byte[length];
 stream.Position = 0;
 stream.Read(data, 0, (int)length);

 //copy data to new stream
 MemoryStream nwStream = new MemoryStream();
 nwStream.Write(data, 0, data.Length);

 //Disposing the stream
 data = null;
 nwStream.Dispose();
 stream.Dispose();
 GC.Collect();// Disposed all the objects even though memory gets hold up in task manager.  
Natalie Hedström
  • 2,607
  • 3
  • 25
  • 36
Karthikk
  • 326
  • 2
  • 7

0 Answers0