ANN.: Beta 1.0 of Weak Reference Extension Module is nowavailable

Karsten Schneider k at felinity.com
Sun Nov 19 01:06:26 EST 2000


graham wrote:

> Like Johann I find weak references hard to fathom -- at least for their
> utility.

Weak references can help in the context of Python, because the GC (correct me
if I'm wrong) still depends on reference counts. Which means that if an
instance has already been reclaimed by the normal non-cirular method, the
memory is available instantly, and the GC doesn't have to look at it again
later. This saves CPU cycles and keeps the memory footprint of running
applications down.

For example: if you are dealing with deeply nested tree structures with back
references (XML documents come to mind), you don't have to wait for the GC to
do its thing. And when we're talking about rapidly changing structures, such
as processing lots of different XML documents, the garbage can pile up
quickly. And in a server environment... [fill-in the blank.]

Which is also why Smalltalk programmers know to reuse objects in loops,
rather than repeatedly create/drop objects.

[As a side note, some XML DOM implementations use lookups in a separate table
to avoid circular references.]

In other words, weak references in Python are all about control, and I
definitely think there's some value in that. So, thanks to Alex.

However, I have a question about the implementation. The way I understand it,
it hooks into Python's [de-]allocation mechanism to make sure weak references
don't point to objects that no longer exist. Does this require a search
through all the weak references for each deallocation? If so, that sounds
like a new performance problem.

And of course, is the Python team considering adopting this implementation
for the next release of Python?

--K




More information about the Python-list mailing list