RE: [Zope] recursive python script = Memory Leak?
[ Andrew Altepeter]
Are there any tricks/quirks in recursive python scripts I should know about? It appears that one section of this list isn't being deleted, so when the script is called again (i.e. starting the recursive algorithm again), the list that is initially create is the list from the previous call.
Try adding a "depth" parameter to track the recursion level. For the first iteration, have the method print or otherwise log the list, so you can see what it starts out as.
I'll put the code here so hopefully someone can point out an (obvious) bug :-)
Oh, the list that I'm building is of the form: [[object, [objects children]]] And, it's necessary to have the second outer list.
... #create a new child_q new_queue = [[context, queue]]
if (context.is_root != 1): return context.aq_parent.getRootedMenuList(new_queue) else: return new_queue
It looks to me like everything should be released by the time the thing returns from recursion. I would be the most concerned about "queue" and "new_queue" because they seem to have the most potential for keeping references hanging around - who knows what references Zope may construct once the thing returns? So the one thing I would try first is this -
if (context.is_root != 1): return context.aq_parent.getRootedMenuList(new_queue) new_queue = None #just in case ... else: return new_queue
Where does "is_root" come from? BTW, you do not need the parens around the condition expressions in the if statements. Cheers, Tom P
Hi Tom, Thanks for your help with this memory leak. After looking into it a bit further, it turns out that the leak is with Silva. I'll be asking the silva-general list about this soon :-)
Try adding a "depth" parameter to track the recursion level. For the first iteration, have the method print or otherwise log the list, so you can see what it starts out as.
Thanks for that tip; I've started using it for other recursive scripts since this one. [snip my recursion code]
It looks to me like everything should be released by the time the thing returns from recursion. I would be the most concerned about "queue" and "new_queue" because they seem to have the most potential for keeping references hanging around - who knows what references Zope may construct once the thing returns? So the one thing I would try first is this -
if (context.is_root != 1): return context.aq_parent.getRootedMenuList(new_queue) new_queue = None #just in case ... else: return new_queue
Where does "is_root" come from?
is_root is a property that all 'BethelMenu's have...it's a way for me to determine whether the current menu is the root menu or not, without having to do: if (context.aq_parent.meta_type != 'BethelMenu'): #we know context is the root menu
BTW, you do not need the parens around the condition expressions in the if statements.
Yup. I do prefer parens, though. I feel it helps me separate the expressions better. Thanks, Andy
Cheers,
Tom P
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
participants (2)
-
Andrew Altepeter -
Passin, Tom