c# - 包装另一个流的 Stream 的实现

标签 c# .net vb.net filestream out-of-memory

好吧,我想我必须制作一个与我在 Out of memory exception while loading images 上找到的问题相关的三部曲。

第二部分来了。

根据答案 - 对上述帖子的评论,迟早任何计算机在执行我的代码时都会耗尽内存。 :(

但感谢Google我找到了一种应用 WrappingStream Implementation. 的方法根据作者的说法

The BitmapImage keeps a reference to the source stream (presumably so that you can read the StreamSource property at any time), so it keeps the MemoryStream object alive. Unfortunately, even though MemoryStream.Dispose has been invoked, it doesn't release the byte array that the memory stream wraps. So, in this case, bitmap is referencing stream, which is referencing buffer, which may be taking up a lot of space on the large object heap. Note that there isn't a true memory leak; when there are no more references to bitmap, all these objects will (eventually) be garbage collected. But since bitmap has already made its own private copy of the image (for rendering), it seems rather wasteful to have the now-unnecessary original copy of the bitmap still in memory.

所以我有几个问题。 (在开始投票之前,请记住我是新手!)

我可以使用 WrappingStream 类来避免内存不足错误吗? 如果第一个是真的,我怎样才能采用它并让它与我的 example? 一起工作?

谢谢

最佳答案

Could i use the WrappingStream class to avoid out of memory errors?

不,它针对的是不同的问题。

关于c# - 包装另一个流的 Stream 的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4855858/

相关文章:

c# - Infopath 2013 代码中 FileQueryConnection 的转换错误

c# - 在 C# 中查找匹配的单词

c# - 数组索引越界错误C#

c# - 是否可以将 WPF WebBrowser 与其他 UIElement 重叠?

asp.net - cType : string to date throwing InvalidCastException (ASP) (VB. NET)

c# - 将偶数键和奇数值数组转换为字典的最优雅方法?

c# - 从 .NET Web 服务中抛出异常

C# 内存模型和非 volatile 变量在其他线程创建之前初始化

javascript - 服务器调用一些(但不是全部)客户端方法

asp.net - UpdatePanel崩溃,其他更新面板不起作用