gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:40:51 25 4
gpt4 key购买 nike

好吧,我想我必须制作一个与我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com