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

Hi,

I am not a PERL expert hence i need someones help. I have been asked to see memory leak in our application. I found massive memory leak in our application. Following is scenario:

Our application is using Perl TK too. We have certain forms which are generated dynamically using all infor regarding test box/lenth etc. from configuration file. It will be generated only when you try to visit those pages. When first time user visits these pages on an order it takes aprox 14 MB. Then when i closed the order opened new created new order with same data it increased by 6 MB aprox and keep adding by 6 MB for all subsequent orders. (Data for each forms are stored in hash.)

I am not able to understand why it's happenning because whenever i come out of order it returns from all sub routines. Therefore all hash should be freed up, created to store data of order, for next time usage. As i read comments about memory leak, says that laxical varible are freed for next time usage (for optimization). But in my case it is not freed up rather keep increasing everytime.
I will appreciate your cooperastion.

Thanks,
Raj.

Replies are listed 'Best First'.
Re: Memory Leak
by Zaxo (Archbishop) on Oct 10, 2002 at 23:48 UTC

    You've given us the freedom to speculate endlessly by not showing code.

    Here's the answer: you have a hash which is never emptied and each time data is added, it grows. Reset it with %hash = (); between forms.

    I could be only guessing ;-)

    After Compline,
    Zaxo

Re: Memory Leak
by l2kashe (Deacon) on Oct 11, 2002 at 03:03 UTC
    Zaxo is right, in that there could be endless speculation as to what the problem actually is without seeing code, so here is my guess

    Where the rate of growth is constant as opposed to variable, i.e. it always increases by 6MB, try looking for a file {conf, log, template, etc...} of about 6MB in size. For whatever reason I dont think it is a hash that is growing, but either an array (being push()'ed into without being cleaned) or a scalar (appended to via .= or something similar) that is the issue..

    thats just a hunch without code, but its an easy mistake to make...

    P.s As a starting point look for global variables, not local variables within the subs, as well as verify that the spelling of the vars used in the subs matches the vars localized. Find all vars that aren't my()'d or local()'d, and track those through the code.

    /* And the Creator, against his better judgement, wrote man.c */
Re: Memory Leak
by ff (Hermit) on Oct 11, 2002 at 03:12 UTC
    Answers or right answers? I'll attempt one of the former.

    Is your program under control of perlmod/Apache somehow and perhaps there is only one perl program ever running which, because it never finishes therefore never does things (close things) you assume happen at a program's end? And therefore your hash keeps accumulating new entries? Can you count the number of keys in your hash with each new invocation?

    Brig