Prevent the GC from compacting the heap #84625
-
Hi, I am interested in configuring the GC so that allocated objects are not moved around memory once created. I want them to live in the same address throughout their lives span. However, I want them swept once they are no longer used (whenever the GC thinks it is best). I think that in GC jargon, this translates to disabling compacting. I'm happy by just achieving this for applications targeting After researching a bit, I think there are two possible ways. I would like to know if you think they would work and if you have any other advice. My intent is not to run this in production, and I understand that this is possibly not how the runtime should ever be configured. First approach: AFAIK, the Large Object Heap is never compacted, which is what I want. I could adjust the Large Object Heap Threshold to 1 or 0 bytes, so all objects are allocated in this way. This would also require setting Second approach: I read here that one of Mono's GC does not compact the memory. Also, this runtime's option allows changing the GC implementation providing it in a DLL. I am unsure if the Boehm GC could be set that way for applications targeting net7.0 in x86-64/Linux. Any thoughts on which one could be easier to get working, or any other advice could be really helpful. Thanks for your time! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The easiest way to do this is to modify the place that decides whether the compact, force it to never compact and build your own GC with this modification. Look for
The LOH threshold can be only set higher than the default. It cannot be set lower.
Replacing CoreCLR GC with Boehm GC would be a major project (months of work to even build a working prototype). |
Beta Was this translation helpful? Give feedback.
The easiest way to do this is to modify the place that decides whether the compact, force it to never compact and build your own GC with this modification. Look for
decide_on_compacting
in gc.cpp.The LOH threshold can be only set higher than the default. It cannot be set lower.
Replacing CoreCLR GC with Boehm GC would be a major project (months of work to even build a working prototype).