如何在vb.net中释放内存 [英] how to free memory in vb.net

查看:554
本文介绍了如何在vb.net中释放内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当系统显示内存不足时如何在vb.net中释放内存。

如何从vb.net中的系统内存转储中释放vb.net中的内存

how to free memory in vb.net when system show low memory.
how to relese memory in vb.net from system memory dump in vb.net

推荐答案

您不需要在.NET中释放或释放内存,除非您在讨论非托管内存,这取决于非托管API。

这是由垃圾收集器。请参阅: http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29 [< a href =http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29target =_ blanktitle =New Window> ^ ]。



我希望你明白:如果没有足够的内存,那还不够。但是,您可以按照一次使用较少的方式设计应用程序。首先,您需要消除内存泄漏。有人认为,如果你不释放内存,托管代码中就不可能发生内存泄漏。这不是真的。当一些对象变得无法访问时,内存被回收(参见上面引用的文章)。您的代码可以收集越来越多的可访问但不可用的对象,因此它们不会被检测为未使用和销毁。



详情请见我过去的答案:

摆脱导致内存不足的公共静态列表的最佳方法 [ ^ ],

MDI表单中的内存管理 [ ^ ],

WPF DataBinding中的内存泄漏 [ ^ ],

推迟循环中的变量会导致内存泄漏? [ ^ ],

Garbage collectotion负责所有的内存管理 [ ^ ]。



-SA
You don't need to free or release memory in .NET, unless you are talking about unmanaged memory, which is up to unmanaged APIs.
This is done by the Garbage Collector. Please see: http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29[^].

I hope you understand: if there is no enough memory, it's not enough. However, you can design your application the way it uses less at a time. First of all, you need to eliminate memory leaks. Some think that, if you don't free memory, memory leaks are impossible in the managed code. This is not true. Memory is reclaimed as some objects become unreachable (see the article referenced above). Your code can collect more and more reachable but not usable objects, so they cannot be detected as unused and destroyed.

For further detail, please see my past answers:
Best way to get rid of a public static List Causing an Out of Memory[^],
Memory management in MDI forms[^],
Memory leak in WPF DataBinding[^],
deferring varirable inside the loop can cuase memory leak?[^],
Garbage collectotion takes care of all the memory management[^].

—SA


这篇关于如何在vb.net中释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆