Suppressing C# garbage collection

后端 未结 6 1075
挽巷
挽巷 2021-02-08 09:26

My application allocates a large amount of memory (millions of small objects totaling several gigabytes) and holds onto it for a long time.

  1. Is .NET wasting time ch
6条回答
  •  我在风中等你
    2021-02-08 09:52

    You can measure this using Performance Monitor. Open perfmon and add the .NET CLR Memory related performance counters. These counters are process specific and with them you can track the number of collections and sizes of the various generations and more spefically for you the "% Time in GC". Here is the explain text for this counter:

    % Time in GC is the percentage of elapsed time that was spent in performing a garbage collection (GC) since the last GC cycle. This counter is usually an indicator of the work done by the Garbage Collector on behalf of the application to collect and compact memory. This counter is updated only at the end of every GC and the counter value reflects the last observed value; its not an average.

    If you watch these counters while running your program, you should have answer for the frequency and cost of the GC due to your memory decisions.

    Here is a good discussion of the various GC Performance Counters. It seems that 10% is borderline okay.

提交回复
热议问题