What triggers a gen2 garbage collection?

前端 未结 2 1256
孤城傲影
孤城傲影 2021-02-04 01:54

I have an odd situation I am trying to figure out.

The Genesis:

I am running my program on a physical machine with 16 cores and

2条回答
  •  天涯浪人
    2021-02-04 02:23

    As I recall, the Client GC is the default. My experience with it is that it doesn't let the heap get very large before collecting. For my heavy duty processing applications, I use the "server" GC.

    You enable the server GC in your application configuration file:

    
    
      
        
      
    
    

    That makes a huge difference in performance for me. For example, one of my programs was spending upwards of 80% of its time in garbage collection. Enabling the server GC dropped that to just a little over 10%. Memory usage went up because the GC let it go, but that's fine for most of my applications.

    Another thing that will cause a Gen 2 collection is the Large Object Heap. See CLR Inside Out: Large Object Heap Uncovered. In a nutshell, if you exceed the LOH threshold, it will trigger a Gen 2 collection. If you're allocating a lot of short-lived large objects (about 85 kilobytes), this will be a problem.

提交回复
热议问题