RE: [Python-Dev] Why aren't more things weak referencable
Guido van Rossum wrote:
For strings at least, perhaps it is time to bite the bullet and include weak reference support directly. Weak reference support ups the per string memory overhead from five words (ob_type, ob_refcnt, ob_size, ob_shash, ob_sstate) to six. The whole concept of weak dictionaries is much more useful when strings can be used as keys and/or values.
Hmm... it is a high price to pay to add another word (*and* some extra code at dealloc time!) to every string object when very few apps need them and strings are about the most common data type. And since they're immutable, what's the point of having weak refs to strings in the first place? (Note that the original poster asked about *subclasses* of strings.)
Perhaps there should be a standard weakly-referenceable proxy whose sole purpose in life would be to wrap objects that can't be directly weakly referenced. Kind of the opposite of ProxyTypes - it would have an internal strong reference to the object.
This could be done transparently as well - if creating an instance of ReferenceType would raise a TypeError, we take a hit and wrap the object.
Delaney, Timothy C (Timothy)