Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: How to deal with the fact that Perl is not releasing memory

by kcott (Archbishop)
on Jul 07, 2013 at 07:56 UTC ( [id://1042972]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to deal with the fact that Perl is not releasing memory
in thread How to deal with the fact that Perl is not releasing memory

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1042972]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-23 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found