在WinRT中使用流时不消耗内存消耗?

时间:2016-02-12 13:41:55

标签: c# windows-runtime

在将流读取到字节数组并将相同的字节数组保存到流时,我面临内存消耗问题。即使在处理之后,内存也会被占用,它在任务管理器中显示大约150MB(使用WinRT)。我正在寻找一个好的解决方案。请仔细查看代码。

 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.  

0 个答案:

没有答案