python gc.disable
禁用自动垃圾收集。据我了解,这会产生相当多的副作用。为什么会有人想要禁用自动垃圾回收,没有它怎么能有效地管理内存?
最佳答案
禁用垃圾收集器的一个用途是在计时代码性能时获得更一致的结果。 The timeit
module这样做。
def timeit(self, number=default_number):
if itertools:
it = itertools.repeat(None, number)
else:
it = [None] * number
gcold = gc.isenabled()
gc.disable()
...
In Python2直到 Python3.2 gc.disable()
也用于避免a bug caused by garbage collection occurring between fork
and exec
.该问题似乎已在 Python3.3 中得到解决无需调用 gc.disable()
.
关于python - 为什么禁用垃圾收集器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20495946/