Why disable the garbage collector?

后端 未结 4 1621
死守一世寂寞
死守一世寂寞 2021-02-07 00:09

Pythons gc.disable disables automatic garbage collection. As I understand it, that would have quite some side-effects. Why would anyone want to disable automatic garbage colle

4条回答
  •  佛祖请我去吃肉
    2021-02-07 00:40

    The problem with an enabled GC always is that you do not know when it will happen. So if (a part of) your program is time-critical, needs real-time, etc., then you can disable the GC for the time (that part of) your program runs.

    Whether you want to switch the automatic GC on again later or if you prefer to do it manually by calling gc.collect() is of no concern to that question.

    Also, some programs are designed to run only a very short time, so that maybe the developer can assure that there cannot occur any memory problem during that time (consider programs like ls); then that whole GC aspect can be neglected in favor of performance.

提交回复
热议问题