I apologize in advance if this is not the right mailing list.  I
looked through the myriad of perl's mailing lists and couldn't find
anything for advanced internal knowledge outside of this xs list.

We have a rather large object/reference graph of blessed objects and
make use of circular references.  This is a legacy app which runs on
perl 5.8 and mod_perl.  Because of hundreds of thousands of objects
which are loaded and the persistence of the apache child processes, we
are facing memory leaks over time.

Basically, in a simple example, there are parent->child->parent
associations.  Things are not always loaded in a hierarchical order,
so one create the child and then load the parent.  (It's a home grown
ORM system).

We recently went down the path of weakening the child to parent
association end of the graph, though allowing both to be discarded as
they go out of scope.  The issue we're facing is that at times during
the rather large/complex request cycle, we still retain reference to
the child and when trying to associate to the parent, we of course get
an undefined reference.

One solution is to use a proxy with AUTOLOAD as a replacement for the
weak references and though check for such undefined associations on
both sides.  This is a huge project due to the various ways we
interact with the object and we'd love to see if there is a better
way.

One way I'm thinking of is to overwrite the DESTROY method and capture
the parent destruction before it has a chance to disassociate itself
from the child.  What I want to do in that case, is instead of leaving
an undefined reference, replace all references with a pointer to a
proxy mentioned above, allowing it to autoload next time around if the
destructed parent is accessed again.

Looking at devel::peek, I can see what seems to be list of referents
to the object, so that information is I believe maintained.  What I'd
love to find out whether it's possible, is for me to walk the list of
graph of referents and replace all references to the object being
destroy with a proxy and then allow the object to go out of scope.

Any ideas if this is possible and where to look (I've looked around,
but haven't found any documentation/writing of such).  Or is there a
more elegant way of accomplishing this?

Below is a link to some sample code
http://gist.github.com/408224


Thanks and apologies again if this doesn't belong here.  If so, let me
know where  the best place to post this might be.

Thanks.

Ilya

Reply via email to