I obviously have a version without the memory issue.
The programming flexibility is indeed the win.
def primes ():
yield 2
yield 3
f = {}
n = 5
for p in primes():
if p == 2:
continue
p2 = p*p
while n < p2:
if n in f:
double_p = f.pop(n)
m = n + double_p
while m in f:
m += double_p
f[m] = double_p
else:
yield n
n += 2
f[n] = 2*p