Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Fixing leaks with a flush memory call in perl?

by true (Pilgrim)
on Jun 12, 2003 at 04:32 UTC ( [id://265276]=perlquestion: print w/replies, xml ) Need Help??

true has asked for the wisdom of the Perl Monks concerning the following question:

I learned my lesson on strict a while ago (thanks monks). And all my new code has been under strict. Now i watch "top" ,on my linux server. I see my memory leaking from all the old code i haven't fixed yet. I still have a long way to go before i can rewrite everything. Until i do, can i add some sort of flush command to the end of my perl (CGI) until i rewrite them? I am assuming my bad code is what is causing all this lost memory. The more traffic i get, the more frequently i have to restart the server (like every couple of weeks now).

Any ideas on a temp fix with memory flushing till i rewrite under strict? Is this possible or WAY off?

Mostly, my code calls variables into the main namespace (without using my) the program closes and i'm guessing the allocations stay open b/c of lack of "my".

jtrue

  • Comment on Fixing leaks with a flush memory call in perl?

Replies are listed 'Best First'.
Re: Fixing leaks with a flush memory call in perl?
by PodMaster (Abbot) on Jun 12, 2003 at 06:00 UTC
    How is that possible?
    Mostly, my code calls variables into the main namespace (without using my) the program closes and i'm guessing the allocations stay open b/c of lack of "my".
    If the program closes, how can "allocations stay open" (whatever that may mean)?

    Here's how it works, your web server starts your perl program, writes stuff on your program's STDIN, reads off your programs STDOUT, and transmits that info to the client (hello HTTP). When your program ends, all the memory it was using is freed (on one of my apaches on win32, apache actually leaks memory every time it runs a perl/cgi program).

    You wouldn't happen to be using mod_perl by any chance? If so you shouldn't run this program (I wouldn't).

    There is no "flush" command (perl memory managment doesn't work like that). You have to fixup/rewrite your program, or live with it.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Fixing leaks with a flush memory call in perl?
by daeve (Deacon) on Jun 12, 2003 at 05:46 UTC
    Try Super Search using "memory leak" and "memory flush". They both bring up quite a few nodes that may apply to your situation.

    There is some info in Garbage-collecting with closures that you may find helpful if you're running perl earlier than V 5.8.0.

    HTH
    Daeve

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://265276]
Approved by sauoq
help
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-04-24 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found