Do value types get Garbage collected?

后端 未结 3 951
青春惊慌失措
青春惊慌失措 2020-12-08 02:55

I know that reference type will be garbage collected. I wanted to know whether value types will also be garbage collected from the stack?

3条回答
  •  没有蜡笔的小新
    2020-12-08 03:26

    Assuming you mean "garbage collected" in the sense of the garbage collector checking if they are alive and then reclaiming the memory then the answer is no they are not "garbage collected".

    The reason is that memory on the stack is automatically reclaimed as stack frames are removed.

    Have a read of this article: http://en.wikipedia.org/wiki/Stack_%28data_structure%29#Hardware_stacks

提交回复
热议问题