简体   繁体   English

Windows任务管理器确定程序的内存使用情况有多可靠?

[英]How reliable is windows task manager for determining memory usage of programs?

Can I use task manager to detect huge memory leaks? 我可以使用任务管理器来检测巨大的内存泄漏吗? I have a small text parsing program that shows memory usage of around 640K when I launch it. 我有一个小文本解析程序,当我启动它时显示大约640K的内存使用量。 When I parse a file and index it the memory usage grows depending on the size of the file. 当我解析文件并将其编入索引时,内存使用量会根据文件的大小而增加。 Then when I "clear" the index, my memory usage drops down to around 1400K. 然后当我“清除”索引时,我的内存使用率下降到1400K左右。 After this point, I can add as many files as I want and when I clear the index, memory usage drops down to this 1400k level + or - a ~5%. 在此之后,我可以添加任意数量的文件,当我清除索引时,内存使用量下降到1400k级别+或--a~5%。

This is after I made a change in my program. 这是在我改变程序之后。 Before the change the memory usage would continue to go up every time I indexxed some files then cleared. 在更改之前,每次我索引一些文件然后清除时,内存使用量将继续增加。 So after many clears, the memory use of my program was growing and growing. 因此,经过多次清理后,我的程序的内存使用量不断增长。

I realize that this is probably a "hackish" way to profile my app but I'm a student and all I've been able to find are commercial profiling tools which are out of reach. 我意识到这可能是一种“hackish”方式来描述我的应用程序,但我是一名学生,我所能找到的是商业性能分析工具,这是遥不可及的。 I've also read about valgrind which is linux only and I'm developing on windows. 我也读过关于valgrind的内容,这只是linux而且我正在开发Windows。 Is using the task manager accurate at all or am I misguided? 完全使用任务管理器还是我被误导了?

The TaskMgr is way too crude for this purpose. 对于这个目的,TaskMgr太粗糙了。 Especially if you have a lot of dynamic allocations and deallocations which will lead to a highly fragmented heap memory, in which case, it is hard to differentiate between leaks and natural growth of the heap due to fragmentation. 特别是如果你有很多动态分配和解除分配会导致高度分散的堆内存,在这种情况下,由于碎片,很难区分泄漏和堆的自然增长。 You should use win32 API calls to inspect the total amount of memory allocated by your application. 您应该使用win32 API调用来检查应用程序分配的内存总量。 Some years ago, when I used to still have problems with memory leaks (don't have those anymore thanks to RAII), I used to put at the start of the main() a little piece of code that queried for the total amount of memory blocks allocated on the heap, and then query it again at the very end of the main() function, if the two values didn't match, I would report a "memory leak of X bytes" error at that point. 几年前,当我以前仍然遇到内存泄漏问题时(由于RAII而没有那些),我曾经在main()的开头放了一小段代码来查询总量在堆上分配的内存块,然后在main()函数的最后再次查询它,如果这两个值不匹配,我会报告此时“X字节的内存泄漏”错误。

If you want to do that, you can use either GlobalMemoryStatuxEx or a HeapWalk . 如果要这样做,可以使用GlobalMemoryStatuxExHeapWalk The former is simpler to use and faster, but more crude, while the latter is more precise, but much more extensive. 前者使用起来更简单,速度更快,但更粗糙,而后者更精确,但更广泛。

TaskMgr is an extremely crude tool, but it is useful nonetheless. TaskMgr是一个非常粗糙的工具,但它仍然很有用。 If you have memory leaks in the one megabyte range, then it is probably good enough to tell that you have them. 如果你在1兆字节范围内有内存泄漏,那么告诉你拥有它们可能已经足够了。 But, eventually, you'll be looking for leaks in the 10 kilobyte and under ranges, and TaskMgr is useless for those. 但是,最终,你会在10千字节和以下范围内寻找泄漏,而TaskMgr对那些无用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Glowcode内存使用数量与Window Task Manager不同 - Glowcode memory usage number is different from Window Task Manager 如何获取 Windows 中每个正在运行的进程的“专用 GPU 内存”编号(与 Windows 任务管理器中显示的编号相同) - How to get the "Dedicated GPU memory" number for every running process in Windows (The same numbers that are shown in the Windows Task Manager) Windows Task Manager显示进程虚拟内存的哪个部分 - What part of the process virtual memory does Windows Task Manager display 扩展任务管理器Windows 8 - Extending Task Manager Windows 8 如何从32位进程中获取64位进程的可靠内存使用信息? - How to get a reliable memory usage information for a 64-bit process from a 32-bit process? 当前内存使用显示总是比任务管理器多约 14MB - Current memory usage display is always ~14MB more than task manager 为什么我的项目/VS/任务管理器都显示不同的 memory 用法? C++ - Why does my project/VS/Task Manager all show different memory usage? C++ 在任务管理器上看到分配的 memory - Allocated memory seen on Task Manager Windows 8任务管理器虚拟化选项 - windows 8 task manager virtualization option 堆碎片和Windows内存管理器 - Heap fragmentation and windows memory manager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM