Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to stop .NET garbage collection?

Is it possible for a programmer to programmatically start/stop the garbage collection in C# programming language? For example, for performance optimization and so on.

like image 792
Alex Avatar asked Jun 19 '10 05:06

Alex


2 Answers

Since .NET 4.6 it's possible, there are methods in the GCclass:

GC.TryStartNoGCRegion(...) and GC.EndNoGCRegion().

like image 180
Pollitzer Avatar answered Sep 17 '22 15:09

Pollitzer


Not really. You can give the GC hints via methods like GC.AddMemoryPressure or GC.RemoveMemoryPressure but not stop it outright.

Besides, garbage collection is not that intensive of a process. Programmers very rarely ever worry about it.

like image 23
Paul Sasik Avatar answered Sep 17 '22 15:09

Paul Sasik