在 Python 中清除缓存或内存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43459673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:05:40  来源:igfitidea点击:

Clear cache or memory in Python

pythoncaching

提问by Carl Zheng

I have a really large table need to calculate (10 billion + rows). It's too long to calculate all of them at one time. Therefore, I create a list of break points, and I calculate and store at the end of each step. However, each step costs longer time. I think the reason is the memory or cache, do you have any idea how to deal with in this situation or just how to clear cache or memory?

我有一个非常大的表需要计算(100 亿 + 行)。一次计算所有这些太长了。因此,我创建了一个断点列表,并在每一步结束时进行计算和存储。但是,每一步都需要更长的时间。我认为原因是内存或缓存,您知道如何处理这种情况或如何清除缓存或内存吗?

I reuse the variable for output in the loop, so the variable will not become bigger and bigger.

我在循环中重复使用变量作为输出,所以变量不会变得越来越大。

Thank you so much.

非常感谢。

回答by Camilo

I use to solve this using a line that reset the variable at the end of the process, cleaning the cache:

我使用在进程结束时重置变量的行来解决这个问题,清理缓存:

MyVariable = None