Does a garbage collector collect stack memory, heap memory, or both?

前端 未结 9 2718
独厮守ぢ
独厮守ぢ 2021-02-19 04:13

I read lot of articles about garbage collection and almost all article tells about heap memory. so my question is \"garbage collection collects stack memory or heap memory or bo

9条回答
  •  迷失自我
    2021-02-19 04:35

    You don't cite any particular technologies, but the use is fairly typical across languages.

    The garbage collector only works on the managed heap. There may be multiple heaps in a single process, some of which are not garbage collected.

    Variables allocated on the stack are deallocated when a method returns. The garbage colletor will use those variables to find live references, but it will not collect the memory.

提交回复
热议问题