[Zope] recursive python script = Memory Leak?
Andrew Altepeter
aaltepet@bethel.edu
15 May 2003 08:21:25 -0500
I have a hierarchy of folderish objects, and I wish to generate a list
representing it, starting at some arbitrary point in the hierarchy and
working towards the root.
So, I think: recursion is the way to do it. However, any means that I
try to generate this list introduces a memory leak.
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.
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.
## Script (Python) "getRootedMenuList_recursive"
##parameters=queue
##
#add the siblings
for o in context.objectValues('BethelMenu'):
if (o != queue[0][0]):
queue.append([o,[]])
#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
Thanks for your help!!!!
Andy