C# 和垃圾收集

发布于 2024-12-12 05:06:00 字数 343 浏览 0 评论 0原文

.NET 垃圾收集中肯定有一个我目前还不明白的秘密。 我们的 C# WinForms 应用程序有一个对话框,可通过 OR 映射器工具加载大量对象。这个过程消耗了大量的内存,我们认为大部分内存可能被字符串消耗。当我们打开此对话框时,任务管理器显示 900MB 的内存使用情况,再次执行查询时,我们得到内存不足的异常。哇。

现在我们得到提示,当我们最小化应用程序时,会完成某种类型的垃圾收集。通过执行此操作并再次最大化,应用程序仅消耗 10MB。凉爽的。

但是现在,当我们再次执行查询时,内存消耗突然跳回900MB,并且我们再次出现内存不足异常。

这里发生了什么以及我们如何减少内存消耗?在这种情况下,如何研究并降低内存消耗呢?

There must be a secret in .NET garbage collection that I don't understand as for now.
Our C# WinForms application has a dialog that loads very many objects via a OR mapper tool. This process consumes a lot of memory and we think that most of this memory could be consumed by strings. When we open this dialog, the task menager shows 900MB of memory usage and by doing the query again, we get a out of memory exception. Whow.

Now we got the tipp that some type of garbage collection is done when we minimize the application. By doing this and maximizing it again, the application only consumes 10MBs. Cool.

But now, when we do the query again, the memory consumption suddenly jumps back to 900MB and we get the out of memory exception again.

What happens here and how can we reduce our memory consumption? In such cases, how can the memory consumption be researched and reduced?

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

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

发布评论

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

评论(2

究竟谁懂我的在乎 2024-12-19 05:06:00

有很多 .Net 内存分析器可以帮助诊断此类问题。我最喜欢的是 JetBrains 的 dotTrace

There are a bunch of .Net Memory Profilers available to help diagnose issues like this. My favorite is dotTrace by JetBrains

琉璃繁缕 2024-12-19 05:06:00

您确定所有循环都已完成吗?我知道桌面应用程序中的资源遇到的最大问题是循环卡住或无法成功结束。您确定您的查询正确返回吗?

除了查询之外,您还做更多的事情吗?我会确保您的所有流程都正确开始和结束。

Are you sure all your loops are completing. I know the biggest issue I have had with resources in my desktop applications have been loops that get stuck or do not end successfully. Are you sure your query is coming back correctly?

Are you doing more then just querying? I would make sure all your processes are starting and finishing correctly.

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