I am a little puzzled by how Python allocates memory and garbage collection, and how it depends on the platform. For example, when we compare the following two code fragments:
Fragment A:
>>> id('x' * 10000000) == id('x' * 10000000) True
Fragment 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 place for the first test and in different places in the second test, so their memory locations are different.
But apparently, the performance of the system or the platform affects this because when I try to do it on a larger scale:
for i in xrange(1, 1000000000): if id('x' * i) != id('x' * i): print i break
A friend on the Mac tried this and it worked to the end. When I ran it on a bunch of Linux virtual machines, it invariably returned (but at different times) to different virtual machines. Is this because of scheduling garbage collection in Python? Was it because my Linux virtual machines had less processing speed than the Mac, or the Linux implementation garbage Python collection in different ways?
source share