.net 项目中的非 .net 类需要 .NET GC 说明

发布于 2024-09-15 22:17:11 字数 295 浏览 3 评论 0原文

我正在解决我的应用程序中的一些内存问题,并最终设法弄清楚它的真相。我最近有一个例子,在处理任务时我的进程内存达到了 800mb。我现在已经设法将其稳定在 140mb,这是完全可以接受的。然而,这让我质疑我对 .NET 垃圾收集器的理解。我的内存问题是通过在每次使用后释放 2 个非 .NET 对象(TADOCommand 和 TDataSet - 在 delphi 中)来解决的。这些变量的范围是过程的本地变量,因此我认为它们应该被自动清除,因为没有任何东西可以引用它们。

那么,.NET 如何处理释放非 .NET 对象呢?或者不是吗?

谢谢。

I am combating some memory issues in my app and am finally managing to get to the bottom of it. I have had an example recently where my process memory went up to 800mb when processing a task. I have managed to get this to settle at 140mb now which is perfectly acceptable. However this has made me question my understanding of the .NET Garbage Collector. My memory issue was fixed by freeing 2 non .NET objects (TADOCommand and TDataSet - in delphi) after every use. The scope of these variables are local to the procedure so I presumed they should be cleared up automagically because nothing should have a reference to them.

So, how does .NET handle freeing objects that are not .NET? Or doesn't it?

Thanks.

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

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

发布评论

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

评论(1

·深蓝 2024-09-22 22:17:11

事实并非如此。 .NET 垃圾收集器仅处理托管对象。其他一切都必须用其他东西来清理。

如果这些资源是托管类型封装的,则可以使用 IDisposable 来实现清理。

It doesn't. The .NET Garbage Collector only handles managed objects. Everything else must be cleaned up by something else.

If said resources are encapsulated by managed types, you can use IDisposable to implement the cleanup.

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