gc.collect真的释放内存吗?
我正在尝试使用 gc.collect() 释放内存。但我不太明白它是如何工作的。例如:
在运行 del 和 gc 之前,使用的内存为 58g。运行后,使用的内存仍然是58。看起来没有释放任何内存。我感觉 gc 与关闭 python 并重新启动不同,后者实际上释放了内存。
所以我想知道如何实际释放内存以便我可以加载其他数据?
I am trying to release memory using gc.collect(). But I do not really understand how it works. For example:
Before I run del and gc, the used memory is 58g. After running them, the used memory is still 58. It looks that no memory has been released. I sense gc is different than shutting down python and starting again, which actually release memory.
So I am wondering how to actually release the memory so that I can load other data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的操作系统,它可能不会收回释放的内存。
您可以在 Linux 上尝试 malloc_trim:
Depending on your OS, it may not take back the released memory.
You can try out malloc_trim on Linux: