我想看一个进程是否有内存泄漏,开始是观察ProcessExplorer里面的WorkingSet,后来发现这个不准确,因为它是物理内存(具体指真正用到的字节数还是页面总共的字节数不清楚),会乱变。查网上,有人说Private Bytes是程序自己分配的,已经提交了的总字节数,且不包含共享内存,这个似乎是我想要的了,可是我发现就算程序处于Idle状态,它也会变化几个字节,按道理它应该只有在我进行操作的时候变化才对。其他的参数Virtual Size, WS Private, WS Sharable and WS shared我也没有找到明确的说明。它们的关系我计算了一下,仅仅有一个确定的:WorkingSet=WS Private+WS Sharable。
有没有人对这些参数的物理意义比较清楚,它们的关系如何?另外不要告诉我用其他方法查内存泄漏,其他方法我了解,我就想知道这几个参数的意义和关系。

解决方案 »

  1.   

    推荐的资料:
    Sysinternals Video Library
      

  2.   

    谢谢楼上,我正试着找地方下载Sysinternals   Video   Library,6DVD太大了,也不知道能不能在里面找到答案。刚去SysInternal的网站上查,这个问题好像在那里也是个一直得不到回答而又经常被问的问题。是不是只有微软的人,比如蒋晟才能回答,呵呵。
    http://forum.sysinternals.com/forum_posts.asp?TID=11289Topic: Process Explorer - App Memory Consumption
        Posted: 03 July 2007 at 4:10am 
    Hello,
     
    I trying to figure out the memory consumption of my running application using the Process Explorer v10.21.
    But I feel that the help it provides is lucking some info.
     
    Can you forward me where I can find a detailed description of the columns of the Process Explorer main window or send my data about it?
     
    The main fields I need to be more familiar with are:
    * Private Bytes
    * Virtual Size
    * Heap Bytes
     
    Does the value of any of them are included in the value of the other? 
    ----- 
    Thanks 
    Sharon  
    Hi, Sharon.
     
    This type of inquiry comes up from time to time.  Unfortunately, though it has been discussed I am not aware of any complete comparison or description of the values that Process Explorer or other tools are able to display.
     
    For Virtual Size, the following topic, as well as the link in it, may prove useful:
    "Virtual Memory"
     
    For Private Bytes, Microsoft Windows Internals, Fourth Edition states:
    the Process: Page File Bytes performance counter is actually the total process private committed memory, of which none, some, or all may be in the paging file. (In fact, it's the same as the Process: Private Bytes performance counter.)  
    The PE Help File states:
    Private Bytes represents the amount of private virtual memory a process has allocated and is the value that will rise of a process exhibiting a memory leak bug.  
    For Heap Bytes - not sure what you are referring to - the .NET CLR Memory performance counter for "# Bytes in all Heaps"?  Per MSDN:
    Displays the sum of the Gen 0 Heap Size, Gen 1 Heap Size, Gen 2 Heap Size, and the Large Object Heap Size counters. This counter indicates the current memory allocated in bytes on the garbage collection heaps.  
    Hope this helps...
    Edited by molotov - 03 July 2007 at 5:17am  
    Daily affirmation: 
    net helpmsg 4006 mygreenpaste.blogspot.com  
      

  3.   

    顶。这个问题我也回答不了,但有一点,MVP都不是微软员工,所以蒋晟也不是,呵呵
      

  4.   

    哎,一天不见你成星星了?进化的快啊,呵呵
    据我所知,微软的员工也可以成为MVP。蒋晟有次不是说他跟Bill Gates开会吗?
      

  5.   

    MVP在被微软雇用的时候就失去MVP资格
    想查内存泄漏的话,可以自己写内存分配和释放程序,比如MFC的DEBUG_NEW。一些程序会自己分配一个堆,虽然堆上的内存没有被程序的代码使用,但是还是被程序预留了。.Net程序的堆比Visual C++的堆要大,但是一个进程内的所有模块共享一个托管堆,而且GC会避免内存泄漏的问题,但是还没被GC的程序不再使用的对象也会占内存。
    如果你要检查内存泄漏,你应该重视private bytes和virtual bytes。如果你的程序的内存页交换太多,你应该检查Working Set。
    顺便说一下,你应该用performance monitor来监视性能。你也可以用一个profiler或者注入一个DLL来hook virtualalloc。
      

  6.   

    想问一下老大,MVP被微软雇用的多吗?或者说是不是MVP被微软雇用的可能会大一点呢?
      

  7.   

    等蒋晟再来回答吧。我既不想做微软员工,也不想做MVP,说不定某个时候就离开CSDN了,也说不定以后转行不再搞软件。
      

  8.   

    MVP人数太少,没有统计学意义。
      

  9.   

    做了一下实验,基本搞清楚了。private bytes算是比较理想的一个参数吧。谢谢各位参与,蒋老大都来了;-) 过几天结贴。