如何正确删除python中对象占用的内存?
中看到的,即使使用 del 关键字后,列表也会保留该值。 是的,我已阅读有关 del 声明的官方文档
删除名称会从本地或全局命名空间中删除该名称的绑定
但是如果 del 语句仅删除名称绑定并且实际上并没有释放内存空间那么这样的语句有什么用呢?如何真正释放对象占用的内存?
最重要的是,如果分配给 list 的对象在我们删除它后不会在 list 中消失,那么为什么当我们对其中一个执行 del list1[i] 时,分配为 list1 = list2 的 2 个列表会同时删除它们的元素。
As you can see in the image, a list retains the value even after del keyword has been used.
Yes I have read the official doc on del statement
Deletion of a name removes the binding of that name from the local or global namespace
But if del statement only removed of the name binding and does not actually free the memory space then what is the use of such a statement? and how do you truly free a memory occupied by an object?
most importantly if an object assigned to list does not disappear in list after we delete it then why does 2 list assiged as list1 = list2 will delete their elements simultaneously when we perform del list1[i] on one of them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论