If you stick with standard .NET coding, is there any reason to manually invoke GC or run finalizers?

If you stick to managed code and standard coding (nothing that does unconventional things with the CLR) in .NET, is there any reason to manually call the GC or request to run finalizers on unregistered objects?

The reason I'm asking is because I have an application that is growing in a working set. I wonder if you are calling

System.GC.Collect();

and

System.GC.RunFinalizers();

would help, and if he forced everything that the CLR would not have done, in any case.

+4
source share
6 answers

, . . CLR , , .

: .NET , , , - . , , , GC .

SOS .

, .

+7

@zneak: . , ( ) #.

. , , , , GC, .

+3

, , Dispose/Finalize, (, ).

+2

, , Collect() . . - , , , №2, . COM-, , , . , Dispose(), .

.

+1

In addition, System.GC.Collect (); useful when you want to measure the memory consumption of some containers. For example, you have a repository and a database service that caches indexed pieces of data that are loaded sequentially and synchronously. When your service is under memory pressure, it can upload large chunks of least-used data.

+1
source

Leave it in the CLR. Use some tools to identify the problem you mentioned.

0
source