Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pause Garbage Collection in .NET?

I'm running some performance tests on some .NET code that processes lots of data. I want some tests that ensure the garbage collector isn't influencing my results. How do I temporarily pause the garbage collector?

like image 857
Ludington Avatar asked Dec 06 '22 04:12

Ludington


1 Answers

There is not a way to do this through the BCL APIs.

Turning it off for the profiling of a particular algorithm is also not a great idea because it will yield false results. The garbage collector will run during the execution of your program. Profiling without the GC could hide real problems with your algorithm if it causes lots of garbage collections in the real world.

like image 200
JaredPar Avatar answered Dec 31 '22 21:12

JaredPar