如何手动调用Python的垃圾回收机制gccollect避免shutilrmtree方法产生的垃圾不回收?以下是需要更改的python2代码 shutilcopysubstitute_apk_path protected_apk_path print Deleting temp files if optionsstore_tmp is False
要手动调用Python的垃圾回收机制,可以在调用完shutil.rmtree方法后立即调用gc.collect()。以下是修改后的代码:
import gc
import shutil
shutil.copy(substitute_apk_path, protected_apk_path)
print '[*] Deleting temp files...'
if (options.store_tmp is False):
shutil.rmtree(tmp_dir)
gc.collect()
通过在shutil.rmtree方法后面添加gc.collect(),可以手动触发垃圾回收机制,确保之前产生的垃圾被及时清理。
原文地址: https://www.cveoy.top/t/topic/iUtV 著作权归作者所有。请勿转载和采集!