C# - Garbage Collection

前端 未结 9 902
闹比i
闹比i 2021-01-31 11:15

Ok so I understand about the stack and the heap (values live on the Stack, references on the Heap).

When I declare a new instance of a Class, this lives on the heap, wit

9条回答
  •  独厮守ぢ
    2021-01-31 11:51

    Garbage collection is basically reference tracking. I can't think of any good reason why you would want to change it. Are you having some sort of problem where you find that memory isn't being freed? Or maybe you are looking for the dispose pattern

    Edit: Replaced "reference counting" with "reference tracking" to not be confused with the Increment/Decrement Counter on object Reference/Dereference (eg from Python). I thought it was pretty common to refer to the object graph generation as "Counting" like in this answer: Why no Reference Counting + Garbage Collection in C#? But I will not pick up the glove of (the) Eric Lippert :)

提交回复
热议问题