With a stack and a bunch of pieces of memory, which one does the .NET garbage collector manage?

With a stack and a bunch of pieces of memory, which one does the .NET garbage collector manage?

+3
source share
3 answers

The memory in the heap is managed by the garbage collector. The memory in the stack is deterministic and returns to the pool when it goes beyond.

+3
source

Just a (managed) bunch. The stack may have references to objects, but not the objects themselves.

+3
source

, . " ", . , CLR. , .

The story is complicated by the fact that GC can combine different heaps in a collection. When this happens, the GC moves the memory around, which means that pointers can be nullified. To accommodate this, GC reserves the right to modify links throughout the application, indicating the correct location. In this sense, the GC controls the "stack", since links stored on the stack can change where they indicate.

0
source

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


All Articles