python - 为什么禁用垃圾收集器?

标签 python garbage-collection

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/

相关文章:

.net - 是什么触发了第二代垃圾回收?

ruby - Ruby 1.9 中的垃圾收集器调整

java - 关于 OCA 考试垃圾收集的问题

python - python中带参数的时间函数

Python:Numpy 和 Pandas 将时间戳/数据转换为单热编码

python - 填充特定颜色的矩形内的水印

javascript - 三个 js 场景的 UIWebView Javascript 垃圾收集

Python:将 Unicode-Hex-String 转换为 Unicode

python - 如何将/proc/net/dev 的输出解析为 key :value pairs per interface using Python?

java - 此 java 对象是否符合 List 中的垃圾回收条件