Hi, Martijn Faassen wrote:
The ZODB has a cache, which is simply some of the "recently touched" Python objects in memory.
Why would an XPath string result end up in that cache in the first place?
In think in general smart strings behave somewhat unexpectedly in the face of potentially long-running processes. One is inclined to treat them as strings, but their memory behavior is quite different.
True. But the only way I see that would work around this internally is a weak reference - and Elements are not currently weak referencible. I never tried, but I would imagine that there is an overhead involved in adding a "__weakref__" to the _Element class. IIRC, this adds a dictionary to the class. I could also imagine giving the smart strings a method ".toplainstring()" that would return a plain string value without the parent link. That way, users who want to pass on the string to a potentially long-living place can unlink the string from its parent. Your proposal of configuring this behaviour on a parser (XML parser, not XPath parser) isn't impossible either, since we already pass a _Document (with a parser reference) into the XPath value unpacker. But I'm not convinced that that is the right place for such an option. Doing that in the XPath class looks harder at first sight. Stefan