[Zope] recursive python script = Memory Leak?
Passin, Tom
tpassin@mitretek.org
Thu, 15 May 2003 11:06:11 -0400
[ 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=20
> 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=20
> the previous
> call.
>=20
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 :-)
>=20
> Oh, the list that I'm building is of the form:
> [[object, [objects children]]]
> And, it's necessary to have the second outer list.
>=20
> ...
> #create a new child_q
> new_queue =3D [[context, queue]]
>=20
> if (context.is_root !=3D 1):
> return context.aq_parent.getRootedMenuList(new_queue)
> else:
> return new_queue
>=20
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 !=3D 1):
> return context.aq_parent.getRootedMenuList(new_queue)
new_queue =3D 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