Python内存使用情况 [英] Python memory usage

查看:78
本文介绍了Python内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


只是想知道我何时运行以下代码;


for i in range(1000000):

print i


Python峰值的内存使用量,当范围(..)块结束时

执行内存使用量不会下降下。是否有一种方法可以释放这个范围(..)分配的内存?


我找到了这个文件,但是修复似乎太复杂了。

http:// www .python.org / pycon / 2005 / pap ... hon-memory.pdf


干杯

Hi All,

Just wondering when i run the following code;

for i in range(1000000):
print i

the memory usage of Python spikes and when the range(..) block finishes
execution the memory usage does not drop down. Is there a way of
freeing this memory that range(..) allocated?

I found this document but the fix seems too complicated.

http://www.python.org/pycon/2005/pap...hon-memory.pdf

Cheers

推荐答案

2006年11月7日21:42:31 -0800,placid< Bu **** @ gmail.comwrote:
On 7 Nov 2006 21:42:31 -0800, placid <Bu****@gmail.comwrote:

大家好,


只是想知道我何时运行以下代码;


for i in range(1000000):

打印我
Hi All,

Just wondering when i run the following code;

for i in range(1000000):
print i



问题在于列表使用的所有内存

由范围返回,不会被释放直到for循环退出


试试这个

the problem of that is that all the memory is used by the list
returned by range which wont be freed until the for loop exits

try this


>>导入itertools
for i in itertools.count(1000000):
>>import itertools
for i in itertools.count(1000000):



.... print i


使用迭代器我相信会降低内存使用量

但会杀死你的CPU :)

.... print i

that uses an iterator which I believe will bring down the memory usage
but will kill your CPU :)


内存使用Python峰值,当范围(..)块完成时,
执行内存使用量不会下降。是否有一种方法可以释放这个范围(..)分配的内存?


我找到了这个文件,但是修复似乎太复杂了。

http:// www .python.org / pycon / 2005 / pap ... hon-memory.pdf


干杯


-
http://mail.python.org/mailman/listinfo / python-list


2006年11月7日星期二22:42,placid写道:
On Tuesday 07 November 2006 22:42, placid wrote:

大家好,


只是想知道我什么时候运行以下代码;


for i in range(1000000):< br $> b $ b打印i


Python峰值的内存使用量以及范围(..)块结束时

执行内存使用情况不要下降。是否有一种方法可以释放这个范围(..)分配的内存?


我找到了这个文件,但是修复似乎太复杂了。

http:// www .python.org / pycon / 2005 / pap ... hon-memory.pdf


干杯
Hi All,

Just wondering when i run the following code;

for i in range(1000000):
print i

the memory usage of Python spikes and when the range(..) block finishes
execution the memory usage does not drop down. Is there a way of
freeing this memory that range(..) allocated?

I found this document but the fix seems too complicated.

http://www.python.org/pycon/2005/pap...hon-memory.pdf

Cheers



将范围更改为xrange。通过

比较,它会运行得更快,几乎不会消耗任何内存。我知道你要释放内存的重点然而

在这种情况下没有理由分配内存开始。


Stranegly足够的我的python2.4安装(kubuntu edgy)大约一半的内存

一旦通话结束就会被释放但是如果我再次运行同一个电话

它只会上升到释放内存之前的内存使用情况。因此返回了一些内存,有些内容被python重新使用


Change range to xrange. It will run faster and use up almost no memory by
comparison. I know the point you are getting at for releasing memory however
in this case there is no reason to allocate the memory to begin with.

Stranegly enough on my python2.4 install (kubuntu edgy) about half the memory
gets released as soon as the call finishes however if I run the same call
again it only goes up to the memory usage it was before the memory was
released. So some of the memory is returned and some is reused by python
later.




William Heymann写道:

William Heymann wrote:

2006年11月7日星期二22:42,placid写道:
On Tuesday 07 November 2006 22:42, placid wrote:

大家好,


只是想知道我什么时候运行以下代码;


for i in range(1000000):

print i


Python峰值的内存使用量,当范围(..)块完成时,
执行内存使用量不会下降。是否有一种方法可以释放这个范围(..)分配的内存?


我找到了这个文件,但是修复似乎太复杂了。

http:// www .python.org / pycon / 2005 / pap ... hon-memory.pdf


干杯
Hi All,

Just wondering when i run the following code;

for i in range(1000000):
print i

the memory usage of Python spikes and when the range(..) block finishes
execution the memory usage does not drop down. Is there a way of
freeing this memory that range(..) allocated?

I found this document but the fix seems too complicated.

http://www.python.org/pycon/2005/pap...hon-memory.pdf

Cheers



将范围更改为xrange。通过

比较,它会运行得更快,几乎不会消耗任何内存。我知道你要释放内存的重点但是在这种情况下,没有理由分配内存。


Change range to xrange. It will run faster and use up almost no memory by
comparison. I know the point you are getting at for releasing memory however
in this case there is no reason to allocate the memory to begin with.



多亏了它已修复了一些内存问题。只是

想知道我是否在xrange()块内连续创建不同的BeautifulSoup对象

,此时

对象的内存是否已释放xrange()块,xrange()

块的下一次迭代?


干杯

Thanks for that it has fixed some of the memory problems. Just
wondering if i continuously create different BeautifulSoup objects
within a xrange() block when does the memory get released for this
object, after the xrange() block, the next iteration of the xrange()
block ?

Cheers


这篇关于Python内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆