垃圾收集器是收集堆栈内存还是堆内存? [英] Does a garbage collector collect stack memory, heap memory, or both?

查看:174
本文介绍了垃圾收集器是收集堆栈内存还是堆内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了很多关于垃圾收集的文章,几乎所有文章都讲述了堆内存。所以我的问题是垃圾回收收集堆栈内存或堆内存或两者兼而有之。

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 both".

推荐答案

它收集堆内存。通常,当执行路径到达作用域的末尾时,堆栈内存会自动收集 。例如:

It collects heap memory. Usually, stack memory is collected automatically when the execution path reaches the end of the scope. e.g.:

void fun()
{
  int n; // reservation on the stack as part of the activation record
  ...
} // returning the stack pointer to where it was before entering the scope

事实上,在像C ++这样的语言中,栈分配变量被称为 auto 变量。

In fact, in a language like C++, stack allocated variables are called auto variables.

这篇关于垃圾收集器是收集堆栈内存还是堆内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆