Pythons gc.disable http://docs.python.org/3.3/library/gc.html#gc.disable禁用自动垃圾收集。据我了解,这会产生相当多的副作用。为什么有人想要禁用自动垃圾收集,如果没有它,如何有效地管理内存?
禁用垃圾收集器的一种用途是在对代码性能进行计时时获得更一致的结果。The timeit module http://hg.python.org/cpython/file/a3bdbe220f8a/Lib/timeit.py#l176做这个。
def timeit(self, number=default_number):
if itertools:
it = itertools.repeat(None, number)
else:
it = [None] * number
gcold = gc.isenabled()
gc.disable()
...
在Python2中 http://hg.python.org/cpython/file/b96a6493cecf/Lib/subprocess.py#l1220直至Python3.2 http://hg.python.org/cpython/file/8c9769b17171/Lib/subprocess.py#l1229 gc.disable()
也用于避免由之间发生的垃圾收集引起的错误fork and exec http://bugs.python.org/issue1336。问题似乎已解决Python3.3 http://hg.python.org/cpython/file/9f38bbd4e041/Lib/subprocess.py#l1324无需致电gc.disable()
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)