在木星笔记本中删除del后释放内存 [英] release memory after del in jupiter notebook

查看:45
本文介绍了在木星笔记本中删除del后释放内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用del list_of_df删除了木星笔记本中的一些变量.但是我们意识到内容仍然占用内存.所以我们尝试了%reset list_of_df,但是以前的变量名已经不存在了……除了重启内核以重新收集内存之外,我们别无选择吗?谢谢

I have deleted some variables in jupiter notebook using del list_of_df. But we realize the contents still occupies memory. so we tried %reset list_of_df , but the previous variable names are already not there... Is there nothing we could do but to restart the kernel to recollect the memory? Thanks

进一步: 一般来说,我可能会失去从庞大的木星笔记本代码中删除的内容的跟踪.是否可以检查已删除但仍然占用内存的内容并将其删除?

Further: In a more general, I might have lost track of what I have deleted from a huge jupiter notebook codes. Is it possible to check what have been deleted but still occupying the memory and delete it?

推荐答案

Python与C不同,例如,您必须手动释放内存.而是由

Python isn't like C (for example) in which you have to manually free memory. Instead, all memory allocation and deallocation tasks are handled automatically in the background by a garbage collection (GC) routine. GC uses lazy evaluation, which means that the memory probably won't be freed right away, but will instead be freed only when it "needs" to be (in the ideal case, anyway).

您不应该在生产代码中使用它,但是如果您确实想要,在del列表之后,可以使用

You shouldn't use this in production code, but if you really want to, after you del your list you can force GC to run using the gc module:

import gc
gc.collect()

但是,由于许多不同的原因,它实际上可能无法工作/分配内存.通常,最好让Python自动管理内存而不干扰.

It might not actually work/deallocate the memory, though, for many different reasons. In general, it's better to just let Python manage memory automatically and not interfere.

这篇关于在木星笔记本中删除del后释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆