.NET Compact framework GC Quantum

Charminar, Hyderabad

In my post When does the .NET Compact Framework Garbage Collector run I mentioned that one of the causes for starting a garbage collection is that 1 MB of data has been allocated from the last garbage collection. Essentially we keep a counter which is reset to 0 on each GC and it is incremented each time managed data is allocated. In a subsequent allocation if this counter hits 1 MB then GC is run.

This cut-off value is called the GC Quantum. The default value of the quantum was chosen to be 1 mb keeping in mind low memory applications (which is the typical case for compact framework). However, this value may not be suitable for all types of application. A registry key is provided which can be added/modified to change this.

Using Remote Registry Editor go to the registry key HKLM\Security\.NetCompactFramework\GC on the device and add a new DWORD value named Quantum and enter whatever quantum value in bytes you want to use. Note that the supported range is 64KB to 16MB.

Increase in Quanta value would mean that the GC is run less often but at the same time cost of every GC will go up (as it would crunch more memory). Hence test your application well and watch it under the Remote Performance Monitor to ensure the change in Quatum did not have adverse perf impact.

NOTE: Use this key as a last resort. The GC behaviour mentioned in this post can change or the key can simply be removed in future versions of .NET Compact Framework.

Comments (4)
  1. Kris says:

    Wouldn’t it make more sense to be able to set this on a per application basis?

  2. Susan Wolber says:

    Does this change take effect at next GC or do we need to power-cycle the device for the registry value to be read?

  3. This value is read in at application startup, so next launch of app would pick it up.

Comments are closed.

Skip to main content