如何检测窗体上的所有控件使用了多少内存?

发布于 2024-10-21 03:43:37 字数 68 浏览 2 评论 0原文

假设我在 Windows 窗体上有很多控件。有没有办法知道每个控件使用了多少内存?有没有可以显示内存信息的免费工具?谢谢。

Suppose I have many controls on Windows Form. Is there any way to know how much memory is used for each control? Are there any free tools that can display the memory info? Thanks.

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

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

发布评论

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

评论(3

秋心╮凉 2024-10-28 03:43:37

Windows 窗体控件不仅仅是内存。事实上,由于内存如此便宜且可用,它很少成为瓶颈 - 特别是托管内存。

您需要记住,Windows 窗体控件使用 WIN32 窗口对象,其中包含窗口句柄和各种 WIN32 GDI 对象。它们还作为托管对象存在于堆上,但托管内存使用量不会很大。

为了回答您的问题,您可以使用内存分析器

Windows forms controls are not just memory. In fact with memory being so cheap and available, it is rarely the bottleneck - especially managed memory.

You need to bear in mind that Windows forms controls are using WIN32 window object which contains window handles and various WIN32 GDI objects. They also have a presence on the heap as a managed object but the managed memory usage is not going to be huge.

In order to answer your question, you can use memory profilers.

百善笑为先 2024-10-28 03:43:37

您可以获得有关控件内存使用情况的信息的唯一方法是每个控件都旨在提供此类信息。然而,大多数简单的类(例如“string”)不提供它,您必须猜测或谷歌来确定它的大小。

至于 GUI 控件 - 有些是 HWND 绑定的,有些则不是。有些附有其他手柄,有些则没有。有些具有一些共享资源,因此控件(或组)的第一个实例将增加内存使用量,第二个实例不会,依此类推......

Only way that you could get an info about controls' memory usage is that each control is designed to provide such an information. However, most simple classes such as 'string' doesn't supply it, and you have to either guess or google for determining its size.

As for GUI controls - some are HWND bound, some are not. Some have some other handles attached to them, some don't. Some have some shared resources, so first instance of the control (or group) will increase memory usage, second instance won't, and so on...

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