Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WinRT中使用流时未释放消耗的内存?_C#_Windows Runtime - Fatal编程技术网

C# 在WinRT中使用流时未释放消耗的内存?

C# 在WinRT中使用流时未释放消耗的内存?,c#,windows-runtime,C#,Windows Runtime,在将流读取到字节数组并将相同的字节数组保存到流时,我面临内存消耗问题。即使在处理之后,内存也会被占用,它在任务管理器中显示为大约150MB(使用WinRT)。我正在寻找一个好的解决办法。请同时查看代码 Assembly assembly = typeof(MainPage).GetTypeInfo().Assembly; Stream stream = assembly.GetManifestResourceStream("MemryHoldUp.Assets.Correct.pdf");

在将流读取到字节数组并将相同的字节数组保存到流时,我面临内存消耗问题。即使在处理之后,内存也会被占用,它在任务管理器中显示为大约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.  

在你不高兴之前,试着关闭你的流