I'm a little puzzled how Python allocates memory and garbage-collects, and how that is platform-specific. For example, When we compare the following two code snippets:
Snippet A:
>>> id('x' * 10000000) == id('x' * 10000000)
True
Snippet B:
>>> x = "x"*10000000
>>> y = "x"*10000000
>>> id(x) == id(y)
False
Snippet A returns true because when Python allocates memory, it allocates it in the same location for the first test, and in different locations in the second test, which is why their memory locations are different.
But apparently system performance or platform impacts this, because when I try this on a larger scale:
for i in xrange(1, 1000000000):
if id('x' * i) != id('x' * i):
print i
break
A friend on a Mac tried this, and it ran until the end. When I ran it on a bunch of Linux VMs, it would invariably return (but at different times) on different VMs. Is this because of the scheduling of the garbage collection in Python? Was it because my Linux VMs had less processing speed than the Mac, or does the Linux Python implementation garbage-collect differently?