简体   繁体   English

识别C#应用程序使用的本机内存的所有者

[英]Identify owner of native memory used by C# application

I am working on a C# application which is designed to run in the system tray all the time. 我正在开发一个C#应用程序,它可以一直在系统托盘中运行。 I would therefore like to minimise the amount of memory which the application uses when idle. 因此,我希望最小化应用程序在空闲时使用的内存量。 Using Windows perfmon and the Windows Task Manager I have got some figures for idle memory usage. 使用Windows perfmon和Windows任务管理器我得到了一些空闲内存使用数据。

  • Windows XP TaskManager - Mem Usage - 96,300K Windows XP TaskManager - 内存使用 - 96,300K
  • PerfMon 性能监视器
    • .NET CLR Memory .NET CLR内存
      • # Bytes in all Heaps - 34,513,708 所有堆中的字节数 - 34,513,708
      • # Total committed Bytes - 40,591,360 #Total committed Bytes - 40,591,360
      • # Total reserved Bytes - 50,319,360 #Total保留字节数 - 50,319,360

I think these figures mean that my application has been allocated 96MB of memory by Windows. 我认为这些数字意味着我的应用程序已经被Windows分配了96MB的内存。 50MB of this has been allocated to the CLR. 其中50MB已分配给CLR。 The CLR has handed out 40mb of this. CLR分发了40mb。

Is there any way to work out what the other 46mb of memory which hasn't been assigned to the CLR is being used for? 有没有办法弄清楚尚未分配给CLR的其他46mb内存用于什么? I assume this will be a combination of memory used for loading DLLs into the process and memory used by this native code. 我假设这将是用于将DLL加载到进程中的内存和此本机代码使用的内存的组合。

EDIT: I have download VMMap and found the following. 编辑:我已下载VMMap并找到以下内容。

  • Private 私人的
    • Total - 72mb 总计 - 72mb
    • Managed Heap - 25mb 管理堆 - 25mb
    • Stack - 16mb (Seems quite large) 堆栈 - 16mb(看起来很大)
    • Private Data - 13mb (Not sure what this is) 私人数据 - 13mb(不知道这是什么)
    • Image - 8mb (Mostly .NET DLLs) 图像 - 8mb(主要是.NET DLL)
    • Page Table - 6mb (Seems quite large) 页表 - 6mb(看起来很大)
    • Heap - 3mb 堆 - 3mb

Can anyone suggest an interpretation for the Stack, Private Data and Page Table figures? 任何人都可以建议对Stack,Private Data和Page Table数字进行解释吗?

NOTE: The counters I originally quoted are now showing some bizarre figures. 注意:我最初引用的计数器现在显示了一些奇怪的数字。

  • Windows XP TaskManager - Mem Usage - 43,628K Windows XP TaskManager - 内存使用 - 43,428K
  • PerfMon 性能监视器
    • .NET CLR Memory .NET CLR内存
      • # Bytes in all Heaps - 20mb 所有堆中的字节数 - 20mb
      • # Total committed Bytes - 23mb #Total committed Bytes - 23mb
      • # Total reserved Bytes - 50mb #Total保留字节数 - 50mb

This suggests that the CLR has reserved more memory than has been allocated to the process. 这表明CLR保留的内存比分配给进程的内存多。 Obviously this can't be true so the TaskManager must only be showing what has been paged in at the moment. 显然这不可能是真的,所以TaskManager必须只显示当前被分页的内容。

Note that the difference between the total memory usage (I'm not exactly sure what figure TaskManager is showing; Windows tools have a bad history about using different terms for equal concepts) and the "#Total reserved bytes" may also be used by CLR, just not by the managed heap (so native allocations by the CLR, loaded DLLs, etc. may also account here). 请注意,总内存使用量之间的差异(我不完全确定TaskManager显示的数字; Windows工具有关于使用不同术语来表示相同概念的错误历史记录)和“#Total reserved bytes”也可能被CLR使用,只是不是由托管堆(所以CLR的原生分配,加载的DLL等也可能在这里帐户)。

You may want to checkout Sysinternals VMMap to get more detailed information. 您可能需要签出Sysinternals VMMap以获取更详细的信息。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM