Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi All, Well it looks like jolly St. Nick brought me a memory leak this year. It was something I had a good idea was coming and thought I had a handle on, but apparently not.

What I've got is a set of modules serving as the backend for a CGI::Application-based script running under mod_perl. The trouble is that the modules create datastructures with lots of circular references. Essentially I've got a directed graph implemented as an adjacency list so edges and vertices refer to one another. Furthermore, each vertex in the graph contains a tree where parent and child nodes each hold a reference to one another as a doubly-linked list.

My plan was to use WeakRef to break these circular references, and it seems to work in cases such as my global object cache and in the tree nodes. However, in other cases where the "forward" and "back" references are not so clear, i.e., in my graph edges and vertices, I've run into premature garbage collection leading to some extremely vexing "can't call methodX on an undefined value" errors. So I've removed the trouble making weakenings, but now it looks a lot like I've got a memory leak under mod_perl. My tools for figuring this are admittedly crude, looking at the output from 'top' and watching the memory addresses increase on each invocation of the script. I'm trying to use Apache::Leak as well (calling it in my CGI like leak_test { $my_app->run() };) but it dumps core before providing any useful information: "FILE = 'Wed Dec 24 19:07:45 2003 notice child pid 24391 exit signal Segmentation Fault (11), possible coredump'"

Now I'm very new to Web programming, so perhaps I'm missing an obvious answer, but I need some help solving this. So far I've tried manually calling DESTROY on all my objects in my implementation of CGI::Application::teardown, which, to my surprise, appears not to work. I thought for sure the only drawback was the ugliness of brute-forcing the solution, but apparently I'm missing something about perl's GC. I'm wondering now if I need to traverse my datastructures and manually break those circular references. This would have added benefit since further usages of these modules will face the same problem in some imaginable contexts, so writing code to perform it reliably could come in handy down the road. Or is there a way to tell mod_perl to blow away all object references in a process when the CGI request ends without requiring recompilation of the files on every invocation?

Thanks much, David


"The dead do not recognize context" -- Kai, Lexx

In reply to Mod_perl, Memory Leaks and WeakRef by djantzen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 21:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found