Message395247
This is not a bug, it is intentional design and has been since Python 1.
You are incorrect about x consuming memory "always". If the value bound to x is in use elsewhere, deleting x will save no memory. If the value is not in use elsewhere, it will be garbage collected as soon as x goes out of scope, which will be at the end of the function.
Shifting to block-scope for for-loops has been discussed before, it is not a popular idea and I expect that most people will oppose it. You can search the Python-Ideas mailing list if you want to find out more. If you still feel strongly that this is an enhancement, as it is a major change in language behaviour it would require a PEP to be written.
https://www.python.org/dev/peps/pep-0001/
Even if the PEP was accepted, the earliest it could go into the language would be Python 3.11 or better, and that would likely require a special `__future__` import. |
|
Date |
User |
Action |
Args |
2021-06-07 05:43:32 | steven.daprano | set | recipients:
+ steven.daprano, deb_ctc |
2021-06-07 05:43:32 | steven.daprano | set | messageid: <1623044612.05.0.220372511122.issue44332@roundup.psfhosted.org> |
2021-06-07 05:43:32 | steven.daprano | link | issue44332 messages |
2021-06-07 05:43:31 | steven.daprano | create | |
|