gc.collect()==>python的强制垃圾收集机制(不建议使用强制回收,因为可能导致错误)

作者: python 发布时间: 2022-10-16 浏览: 571 次 编辑
def collect(*args, **kwargs): # real signature unknown

Run the garbage collector.

从内存中释放超出作用范围的变量,不在使用的对象等,写此方法一般表示强制进行回收的,可能导致一些错误,建议不写为好

With no arguments, run a full collection.
The optional argument may be an integer specifying which generation to collect.
A ValueError is raised if the generation number is invalid. The number of unreachable objects is returned.

使用方法:

import gc
gc.collect()