[Python-Dev] d.get_key(key) -> key?

Guido van Rossum guido@python.org
Thu, 06 Jun 2002 09:07:29 -0400


> > An occasional run through the 'interned' dict (in stringobject.c)
> > looking for strings with refcount 2 would do this.  Maybe something
> > for the gc module do handle as a service whenever it runs its
> > last-generation collection?
> 
> This has the potential of breaking applications that remember the id()
> of an interned string, instead of its value.

Ow, good point!  It's also quite possible that there are no outside
references to an interned string, but another string with the same
value still references the interned string from its ob_sinterned
field.  E.g.

    s = "frobnicate"*3
    t = intern(s)
    del t

To solve this, we would have to make the ob_sinterned slot count as a
reference to the interned string.  But then string_dealloc would be
complicated (it would have to call Py_XDECREF(op->ob_sinterned)),
possibly slowing things down.

Is this worth it?  The fear for unbounded growth of the interned
strings table is pretty common amongst authors of serious long-running
programs.

--Guido van Rossum (home page: http://www.python.org/~guido/)