3 ms·
We know that by lexical scoping rules the variable 'a' (which here is a list) is available only to the function body. Once the function call has completed execu
by wruza 4y ago
We know that by lexical scoping rules the variable 'a' (which here is a list) is available only to the function body. Once the function call has completed execution, it no longer exists in memory
The variable no longer exists, but the value does. It depends on a language/runtime, but it’s safe to think about it in terms of “roots” which are non-collectible. A stack (up to the tip) or a special register is one of the roots. Globals table/object is also a root.
When you pin a value (not a variable) into a root, e.g. by putting it on stack (as `return x` does) or by setting it into a global, you prevent it from being destroyed.
Also, this question better fits stackoverflow and likely already answered there, in much more detail than HN could do.
- cpach 4y ago“(…) this question better fits stackoverflow and likely already answered there, in much more detail than HN could do.” By now we have an answer that explains CPython’s assembly, so I think we’re on par. Considering the amount of articles on HN related to business, culture, history, etc, IMHO it can’t hurt with some programming questions every now and then.
- wruza 4y agoNo, I think it’s perfectly fine to ask. I was talking from a viewpoint of chances to get an answer. Some threads here just sink too quickly, while SO specializes in being Q&A-purposed, at least in my experience there.
- cpach 4y agoI think 'dang made some changes a while ago that makes Ask HN posts stay longer on the Ask page.