zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

Python错误 建议 机制 可能 导致 收集 垃圾
2023-09-14 09:06:09 时间
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()