且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在木星笔记本中删除del后释放内存

更新时间:2023-02-02 21:44:53

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.