How do I minimize the length of GC collections?

I need an application that will run smoothly. I have a lot of sequential series of computations that I need to do in short periods of time each, so I don't mind the GC doing the job, and I can even accept more frequent collections, but I need to minimize the length of each GC collection.

I would like (if possible) to have 1 milli-maximum pause of thread activity due to GC every time.

What is the best way to achieve this in .NET (I know .NET is not a technology for such requirements, but if it fits my requirements when optimizing development time savings and flexibility for future specs is a good incentive to give it a try)?

+3


source to share


1 answer


Straight from MSDN page: https://msdn.microsoft.com/en-us/library/ms973837.aspx

The .NET garbage collector provides a high-speed allocation service with good memory utilization and no long-term fragmentation problems, but you can do something that gives you much less than optimal performance. To get the most out of a distributor, you should consider the following methods:

  • Allocate all memory (or as much as possible) that will be used along with this data structure at the same time. Remove temporary allocations which can be avoided with a small difficulty penalty.

  • Minimize the number of references to object pointers, especially those made for old objects.

  • Reduce the density of pointers in data structures.

  • Limit the use of finalizers and then only on "leaf" objects as much as possible. Interrupt objects to help with this if necessary.

  • Regular practice of analyzing your key data structures and maintaining memory usage profiles using tools like the Allocation Profiler will go a long way in making efficient use of your memory and the garbage collector that works best for you.



As Ron mentioned in his comment. You have to be smarter with .NET if you want a lot of GC control.

0


source







All Articles