New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memory leak in random number generation #47313
Comments
#the following code consume about 800M memory, which is normal
n = 100000000
data = [0.0 for i in xrange(n)] #however, if I assign random number to data list, it will consume extra #even if I delete data, only 800M memory released #call gc.collect() does not help, the extra 2.5G memory not released
import gc
gc.collect() only when I quit Python, the memory is released. Same effect if I use |
Confirmed the issue in the trunk right now: (the number between square brackets point to the 'top' information below) facundo@pomcat:~/devel/reps/python/trunk$ ./python
Python 2.6a3+ (trunk:64009, Jun 7 2008, 09:51:56)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
[1]
>>> data = [0.0 for i in xrange(100000000)]
[2]
>>> from random import random
>>> for i in xrange(100000000):
... data[i] = random()
...
>>>
[3] The memory consumption:
[1] 4054 facundo 20 0 5032 3264 1796 S 0.0 0.2 0:00.02 python |
Strongly doubt this has anything to do with random number generation. |
I agree with Tim's comment. The problem's why these floats keep alive |
They stayed alive simultaneously because you stored 100 million of them for i in xrange(100000000):
x = random() the problem would go away -- then only two float objects are |
Here I am confused. 100million floats in a list takes about 800M byte for i in xrange(100000000):
data[i] = random() so it should be 800M plus a float returned by random(). But the problem |
So, 0.0 would be cached, and the 414m+384m would be from the list
And the memory consumption was the big one. Grant, the 800 MB is taken by ONE 0.0, and a list of zillion positions. Furthermore, I did: >>> for x in xrange(100000000):
... i = random() And the memory didn't increase. Grant, take note that there's no gc issue, the numbers stay alive Closing this as invalid. |
Facundo: I understand now. You mean every unique float number used will be an object Thank you very much, On Sun, Jun 8, 2008 at 11:59 AM, Facundo Batista <report@bugs.python.org>
|
Grant, A float takes 64 bits. 100 million floats take 800 MB, *just* the Maybe you shouldn't be building this structure in memory? In any case, you should raise this issue in comp.lang.python, to get advice. Regards, |
Float objects also require, as do all Python objects, space to hold a It is a gc issue in the sense that the float-object free-list is both |
For the record, this was finally fixed with bpo-2862: gc.collect() now clears the free-lists during the collection of the highest generation. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: