.net 内存测量和分析

发布于 2024-10-16 08:03:50 字数 679 浏览 1 评论 0原文

我知道有很多与此相关的问题,所以我会非常具体。 我使用两条指令创建控制台应用程序。创建一个大容量的List并用样本数据填充它,然后清除该List或使其等于null。 我想知道的是,是否有一种方法可以让我在调试时知道/测量/分析,列表被清除和清空后应用程序使用的实际内存是否与列表之前相同创建并填充。我确定应用程序已处理了信息并且 GC 已完成收集,但我可以确定我的应用程序在此之后将消耗多少内存吗? 据我所知,在填充列表的过程中,会分配大量内存,并且在清除内存后,如果其他进程需要它,内存可能会变得可用,但是是否可以测量应用程序在该位置消耗的实际内存结尾? 谢谢

编辑:好的,这是我的真实场景和目标。我正在开发一个 WPF 应用程序,该应用程序可处理通过 USB 设备读取的大量数据。在某些时候,应用程序会分配大约 700+ MB 的内存来存储所有列表数据,它会解析、分析这些数据,然后写入文件系统。当我将数据写入文件系统时,我清除所有列表并处置以前保存大数据的所有集合,以便我可以进行另一次数据处理。我想知道我不会遇到性能问题或最终耗尽所有内存。我对我的程序使用大量内存感到满意,但我对它在几次 USB 处理后使用所有内存感到不满意。 我怎样才能控制这个?在这种情况下是否使用内存或进程分析器?仅使用任务管理器,我看到我的应用程序占用了 800 MB 内存,但在清除集合后,内存保持不变。我知道除非 Windows 需要它,否则这不会下降,所以我想知道我是否可以确定内存已清除并可以免费使用(由我的应用程序或 Windows)

I understand there are many questions related to this, so I'll be very specific.
I create Console application with two instructions. Create a List with some large capacity and fill it with sample data, and then clear that List or make it equal to null.
What I want to know is if there is a way for me to know/measure/profile while debugging or not, if the actual memory used by the application after the list was cleared and null-ed is about the same as before the list was created and populated. I know for sure that the application has disposed of the information and the GC has finished collecting, but can I know for sure how much memory my application would consume after this?
I understand that during the process of filling the list, a lot of memory is allocated and after it's been cleared that memory may become available to other process if it needs it, but is it possible to measure the real memory consumed by the application at the end?
Thanks

Edit: OK, here is my real scenario and objective. I work on a WPF application that works with large amounts of data read through USB device. At some point, the application allocates about 700+ MB of memory to store all the List data, which it parses, analyzes and then writes to the filesystem. When I write the data to the filesystem, I clear all the Lists and dispose all collections that previously held the large data, so I can do another data processing. I want to know that I won't run into performance issues or eventually use up all memory. I'm fine with my program using a lot of memory, but I'm not fine with it using it all after few USB processings.
How can I go around controlling this? Are memory or process profilers used in case like this? Simply using Task Manager, I see my application taking up 800 MB of memory, but after I clear the collections, the memory stays the same. I understand this won't go down unless windows needs it, so I was wondering if I can know for sure that the memory is cleared and free to be used (by my application or windows)

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

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

发布评论

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

评论(4

吻风 2024-10-23 08:03:50

如果您指的是物理内存,则很难测量 Windows 上的“实际内存”使用情况。最有可能的是,您想要其他类似的东西:

  1. 为进程分配的内存量(请参阅 Zooba 的答案)
  2. 分配的托管内存量 - CLR Profiler,或此中列出的任何其他分析器 - 最佳 .NET 内存和性能分析器?
  3. 任务管理器为您的应用程序报告什么

请注意,垃圾收集完成后没有必要显示数量为进程分配的内存 (1) 变化 - GC 可能会保留分配的内存以供将来的托管分配(此行为并非 CLR 特有的内存分配 - 大多数内存分配器都会保留空闲块以供以后使用,除非通过某种方式强制释放它) 。 http://blogs.msdn.com/b/maoni/ 博客是极好的来源有关 GC/内存的详细信息。

It is very hard to measure "real memory" usage on Windows if you mean physical memory. Most likley you want something else like:

  1. Amount of memory allocated for the process (see Zooba's answer)
  2. Amount of Managed memory allocated - CLR Profiler, or any other profiler listed in this one - Best .NET memory and performance profiler?
  3. What Task Manager reports for your application

Note that it is not necessary that after garbage collection is finished amount of memory allocated for your process (1) changes - GC may keep allocated memory for future managed allocations (this behavior is not specific to CLR for memory allcation - most memory allocators keep free blocks for later usage unless forced to release it by some means). The http://blogs.msdn.com/b/maoni/ blog is excelent source for details on GC/memory.

饭团 2024-10-23 08:03:50

Process Explorer 将为您提供所需的所有信息。具体来说,您可能对进程的“私有字节历史记录”图最感兴趣。

或者,可以使用 Windows 的性能监视器来跟踪您的特定应用程序。这应该向 Process Explorer 提供相同的信息,尽管它会让您将实际数字写入单独的文件。

Process Explorer window

(一张图片,因为我可以...)

Process Explorer will give you all the information you need. Specifically, you will probably be most interested in the "private bytes history" graph for your process.

Alternatively, it is possible to use Window's Performance Monitor to track your specific application. This should give identical information to Process Explorer, though it will let you write the actual numbers out to a separate file.

Process Explorer window

(A picture because I can...)

妄断弥空 2024-10-23 08:03:50

我个人使用SciTech Memory Profiler
它有一个实时选项,您可以使用它来查看内存使用情况。它帮助我发现了一些内存泄漏的问题。

I personaly use SciTech Memory Profiler
It has a real time option that you can use to see your memory usage. It has help me find a number of problems with leaking memory.

狼性发作 2024-10-23 08:03:50

尝试 ANTS 分析器。它不是免费的,但您可以尝试试用版。


http://www.red-gate.com/products/ dotnet-development/ants-performance-profiler/

Try ANTS Profiler. Its not free but you can try the trial version.


http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/

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