在Mac OS Terminal中运行python时发生内存泄漏 [英] Memory leak when running python in Mac OS Terminal
问题描述
我刚刚在Mac OS终端中运行了一个python程序,并且出现了异常的内存泄漏.
I just ran a python program in the Mac OS Terminal, and there is unusual memory leak.
程序很简单,像这样:
for i in xrange(1000000000, 2000000000, 10):
i2 = i * i
print i, i2, str(i2)[::2]
if str(i2)[::2] == '1234567890':
break
程序运行时,它将消耗越来越多的内存,直到耗尽我的所有内存.当我终止程序时,我的Terminal.app仍然消耗大量内存,所以我猜这是Terminal.app中的错误?
When the program is running, it consumes more and more memory till it use up all my memory. When I terminate the program, my Terminal.app still consumes a lot of memory, so I guess it's a bug in Terminal.app?
有人有类似的经历吗?
推荐答案
这不是错误;这实际上是一个功能.与许多其他终端仿真器一样,Terminal.app将最近的输出保存在缓冲区中,以便您可以向后滚动(使用向上翻页或滚动条).您可以通过以下方式限制此大小:进入终端"->首选项"->设置",并将回滚限制设置为无限制".
This isn't a bug; it's actually a feature. Terminal.app, like many other terminal emulators, saves recent output in a buffer so that you can scroll back (with page up or the scroll bar). You can limit how large this is by going to Terminal -> Preferences -> Settings and setting the scrollback limit to something other than Unlimited.
这篇关于在Mac OS Terminal中运行python时发生内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!