[Python-3000] weakrefs and cyclic references
Josiah Carlson
jcarlson at uci.edu
Wed May 31 21:10:07 CEST 2006
"tomer filiba" <tomerfiliba at gmail.com> wrote:
> the current gc already detects cyclic referencing between objects,
> and by what i understood, it can free the memory the objects take,
> but __del__ is never call because there's not telling where to
> start the __del__ chain.
Not all cyclic references are easily discovered during assignment, and
could induce huge overhead during assignments in general.
According to my experience, there are two great ways of dealing with
object cycles:
1. never write __del__ methods
2. use weakrefs
The former avoids the __del__ never being called mess assuming that you
don't need any manual cleanup, and the latter allows for arbitrary
cleanup methods.
- Josiah
More information about the Python-3000
mailing list