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

前端 未结 9 2725
独厮守ぢ
独厮守ぢ 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:34

    Heap memory.

    Garbage collection is a method of deallocating memory that isn't being used anymore. Sometimes the "isn't being used anymore" part is tricky. With the stack, as soon as a function returns, we can be confident (excepting programmer error) that the local variables aren't being used anymore, so they are deallocated automatically at that time in nearly every language/runtime.

提交回复
热议问题