When is GC running?

When is GC running? It seems like it works in a certain period of time or when the application requires memory or what?

+3
source share
3 answers

Short answer: if necessary.

Longer answer:

  • If the distribution cannot be performed
  • When AppDomain Unloads
  • When Windows reports low memory
  • When GC.Collect is called

Additionally, finalization may be performed at some point after the GC.

+4
source

from MSFT (see link for more information):

.NET Framework . , . , . . . . , , . .

0

1. .NET Framework .

  • Each time you create an object, the runtime allocates memory for the object from the managed heap. 3. The garbage collector must complete the collection in order to free memory. The engine's garbage collection optimization determines the best time to complete the collection, based on the appropriations made. 4. When the garbage collector performs the collection, it checks the objects in the managed heap that are no longer used by the application and performs the necessary operations to restore their memory.
0
source

Source: https://habr.com/ru/post/1766342/


All Articles