Yes, var
is no longer keeping its previous value from being removed from memory at that point. In CPython (the usual implementation of Python):
- that even usually happens as soon as you reassign
var
because CPython uses reference counting
- that won’t happen for 5 specifically because CPython keeps a certain range of small integers in memory at all times
Your loop won’t fill up memory with old ints in any reasonable Python implementation. In practice, it uses a small, bounded amount of memory.
in theory
In theory, Python has arbitrary size ints, so you’ll use (for example) 2 GB of memory after 216,000,000,000 loop iterations. You’ll never come close to running out of memory for this reason, because there’s not enough time in the universe to get there.