为什么大对象堆会增长而不是抛出异常?

发布于 2024-09-03 00:13:16 字数 396 浏览 4 评论 0原文

在上一个问题中,我问最大化 LOH 上可分配的最大块的可能的编程方式。我仍然看到这些问题,但现在我试图弄清楚为什么 LOH 的大小似乎会增大和缩小,但我仍然看到 OutOfMemoryExceptions,这与其他人报告的由于 LOH 碎片所致的情况相符。

例如,为什么对 StringBuilder.EnsureCapacity 的一次调用可能会抛出 OutOfMemoryException 异常,但其他地方的另一次调用会导致 LOH 的大小扩大(根据性能计数器,它会增大和缩小)?

In a previous question I asked possible programatic ways of maximising the largest block allocatable on the LOH. I'm still seeing the problems, but now I'm trying to get my head around why the LOH seems to grow and shrink in size, yet I'm still seeing OutOfMemoryExceptions that tally with what others have reported as being due to LOH fragmentation.

Why might one call to, for example, StringBuilder.EnsureCapacity throw an OutOfMemoryException for me, but another call from somewhere else result in the LOH expanding in size (according to the performance counters, it is growing and shrinking)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清眉祭 2024-09-10 00:13:16

我不确定,但我会尝试两种方法:

  1. 检查应用程序中分配的非托管内存,并使用 GC.AddMemoryPressure 方法告诉内存管理更好地处理这个问题。
  2. 在大分配调用之前使用 MemoryFailPoint 类。在那里你有机会避免你的申请出现大热潮。释放一些资源并重试。

编辑:第三种方法可能是创建更多应用程序域并在额外的应用程序域中处理大的东西。

im not sure but i would try 2 ways:

  1. check for allocated unmanaged memory in your application and use the GC.AddMemoryPressure Method to tell the memorymanagment to handle this better.
  2. use the MemoryFailPoint Class prior to your big allocation calls. there you have a chance to avoid a big boom in your application. release some ressources and try it again.

edit: a 3rd way may be to create more appdomains and to handle that big stuff in that extra appdomains.

鹤舞 2024-09-10 00:13:16

我转到原始文章并在那里发布了我认为可能是您的问题的内容。去看看吧。

I went to the original article and posted what I think might be your problem there. Go check it out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文