如果我们创建2个变量a,然后是b,那么这些变量如何在python堆中销毁。我们想了解由python解释器完成的内存管理。
简单地说,Python内存管理器对对现有变量的引用计数,如果引用计数等于零,则垃圾收集器会自动为该变量分配空间。
我建议使用以下资源以更好地了解流程:
订单未定义,因为python具有垃圾回收器。要跟踪顺序,您可以添加__del__方法,该方法在Python中称为析构函数方法。当没有对对象的引用并且对象被垃圾回收时,将调用它。
__del__
请参见What is the __del__ method, How to call it?