[ZODB-Dev] Investigating a Zope reference leak... tracking object creation

Ben Last (ZODBDev) zodbdev at benlast.com
Tue Feb 1 05:59:57 EST 2005


Thanks for your help, Chris.

Chris Withers wrote:
> Ben Last (ZODBDev) wrote:
>> <img tal:replace="structure 
>> python:here.scripts.getGraphic(here,environment,'myimage.gif',...)"/>
> And does this provoke your leak?
That I don't know, that's why I'm trying to track instance creation :)  This is the way in which getGraphic is called, and the context in which it returns its results.

> Are any arguments passed which aren't simple strings?
Yes.  The environment, for instance, is a "dictish object" which means that one can access the members as attributes as well as using dict syntax.  We use these in quite a few places; it used to be a home-rolled class but Zope provides the PythonScript.Object, so we use that instead.  "here" is the container.  All the others are simple strings, True/False or None.

>>         #TAL doesn't allow ';' in the source, so we use '$' instead.
> This isn't true, they just need to be quoted by doubling them
Ah, thank you.  One day I'm sure all the tiny TAL tricks like this will be documented somewhere I can find them... :)

>>     if flash is None:
>>         flash = getattr(environment,'flash',False)
> What's flash?
a) a parameter passed in to getGraphic
b) a boolean (strictly, something that evaluates True/False in Python)
c) a flag to indicate that the page is being served to a client that supported Macromedia Flash, and thus certain images may be overridden with Flash replacements.

>>     #Create a dictish object to hold the attributes we return
>>     graphic = Products.PythonScripts.standard.Object()
> I dunno what this is, but it makes me suspicious.
This is used in many places, and there appear to be no leaks of them at all.  We use the dictish objects because otherwise, when writing Python in the context of ZPT, one needs always to be aware of when one's dealing with an object (most cases) or a dict (edge cases) and the number of times that caused problems was growing.  We adopted an idiom by which multiple-value results are always returned as objects.

> What's "doTag" ?
A method that takes the parameters (all are simple except img) and builds an IMG tag that fits the strict requirements of the site.

>>         url =  
>> img.absolute_url().replace(request.BASE1,environment.relpath)
> Hmm, have you tried .absolute_url(1) to replace the stuff above?
No, but thanks for the hint!

>>     except AttributeError:
>>         pass
> Why pass? might be interesting to see what throws attribute errors and why?
It would be on the test site.  In the production environment, problems like this would get reported via Zope error pages to customers, who aren't interested in them!

>>     if swftarget:
>>         graphic = flashOverride(here,swftarget,graphic)
> What does this do?
Looks to see if there's a flash file that can be used to replace the graphic.  In the current test version of the site, all the Flash files have been removed whilst we've been tracking the leak, so in effect it's a no-op.

Regards
Ben



More information about the ZODB-Dev mailing list