From 66d11bd5bac3f5e998de909d4a7d8dadbf44e618 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Thu, 17 Sep 2009 17:26:17 -0400 Subject: [PATCH] notes about garbage collection and class destructors --- special-method-names.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/special-method-names.html b/special-method-names.html index b2714dd..e497e42 100644 --- a/special-method-names.html +++ b/special-method-names.html @@ -777,7 +777,7 @@ def __exit__(self, *args): a class constructor x = MyClass() x.__new__() - +* a class destructor del x x.__del__() @@ -815,6 +815,8 @@ def __exit__(self, *args): MyABC.__subclasshook__(C) +

* Exactly when Python calls the __del__() special method is incredibly complicated. To fully understand it, you need to know how Python keeps track of objects in memory. Here’s a good article on Python garbage collection and how it relates to class destructor methods. You should also read about weak references, the weakref module, and probably the gc module for good measure. +

Further Reading

Modules mentioned in this appendix: