当变量超出范围时,是否意味着它不存在? [英] When a variable goes out of scope does that mean it doesn't exist?

查看:44
本文介绍了当变量超出范围时,是否意味着它不存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我是否理解范围 - 范围外变量(我正在使用 Ruby)是否存在于内存中的某处,或者它是否停止存在(我知道您无法访问它).说范围外变量不再存在是否不准确?

I'm not sure I understand scope - does an out-of-scope variable (I'm using Ruby) exist in memory somewhere or does it stop existing (I know you can't access it). Would it be inaccurate to say that an out-of-scope variable does not exist any more?

也许这是一个哲学问题.

Maybe this is a philosophical question.

推荐答案

如果您使用的是托管语言,那么您不会分配和取消分配内存,因为您认为它不再存在.

If you are using managed language then you don't allocate and unallocate memory so as far as you are concerned it no longer exists.

从技术上讲确实如此,但 GC 往往不是确定性的,因此从技术上讲,很难说它何时真正消失.

Technically it does but GCs tend not to be deterministic so technically it's hard to say when it actually vanishes.

这篇关于当变量超出范围时,是否意味着它不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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