Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

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

Firstly, I'm not a Dancer user. What follows is just a suggestion for something to try; it may not help at all!

In each of your coderefs (get ... sub { ...} [1 instance] and ajax ... sub { ...} [2 instances]), you have code like this:

my @messages = (); ... template '...' => {messages => \@messages};

When they (implicitly) return, @messages will not be garbage-collected while the reference (\@messages) still exists.

I don't know why that reference might still exist. I followed it through Dancer (1.3116) source:

sub template { Dancer::Template::Abstract->template(@_) }

and then through Dancer::Template::Abstract (1.3116) source:

sub template { my ($class, $view, $tokens, $options) = @_; ...

but then, not knowing what templating engine you were using, was unable to continue. I'll leave that as an exercise for you.

You can ensure @messages is garbage-collected by using this code instead (which contructs an anonymous arrayref):

my @messages = (); ... template 'XXX' => {messages => [ @messages ]};

Expanding @messages will incur some overhead but that appears to be very small. Also, you might just be deferring your memory leak problem.

Be aware that memory may not be leaked on every cycle: a linear increase in memory usage may not be occurring at all. It might happen in code that's only run conditionally or perhaps as a result of some exception.

-- Ken


In reply to Re^3: How to deal with the fact that Perl is not releasing memory by kcott
in thread How to deal with the fact that Perl is not releasing memory by carlbolduc

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 learning in the Monastery: (6)
As of 2024-03-19 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found