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

Hello!

I'm using Strawberry Perl 5.18 (32-bit version) on Windows 7. Here goes my code:

# :P for (;;) { system('rrdtool'); }

Though it executes perfectly, I see that amount of memory consumed by perl.exe constantly grows. Could you help me to understand: am I doing smth wrong, is it a memory leak or is it normal beheviour?

Thanks!

Replies are listed 'Best First'.
Re: ``system'' leaking memory
by hdb (Monsignor) on Oct 31, 2013 at 13:40 UTC

    I do not have rddtool, so I am trying

    perl -e "for(;;){system('notepad')}"

    but memory consumption is not growing at all. Could it be that your rddtool does not release all memory?

      Yes, I thought about leaking rdotool. Also I supposed rdotool would execute and exit not interfering with parent perl.exe

        You could emulate this by calling your tool from the same command prompt repeatedly and see whether that will create a similar effect.

        What happens when you try another program, like reg.exe /?
Re: ``system'' leaking memory
by davido (Cardinal) on Oct 31, 2013 at 15:58 UTC

    You could use RRDTool::OO, which makes use of rrdtool's shared library, and avoids the system call altogether. If that still generates a memory leak you'll have to submit a bug report to Tobi Oetiker, as it's probably coming from within the rrdtool code base somewhere.


    Dave

Re: ``system'' leaking memory
by Laurent_R (Canon) on Oct 31, 2013 at 14:13 UTC

    In principle, it should not be doing that unless rddtool has a memory leak. But why are you putting this command in an endless loop with not exit condition?

      It's just an example. In my application rdotool will be called through system a lot, so I decided to test it first.

      I thought system calls are kinda independent from perl process. Am I wrong? All leaked memory stays in parent process?

Re: ``system'' leaking memory
by Laurent_R (Canon) on Oct 31, 2013 at 17:11 UTC

    Having system calls in an endless loop certainly does not seem to be the right thing to do (which is why I asked the question in the first place), but it is really not the same thing as just forking endlessly in a while (1)loop. Admittedly, system will fork a new process each time, but the parent will wait for the child to complete before iterating again into the loop to create a new child, so that you have at most two processes present (and only one really running) at any point of time. It might probably end up exhausting some of the system resources, as not everything may be reclaimed by Perl or the System, but it should be rather slow.

    I just tried this:

    $ perl -e 'system("ls") while 1'

    and monitored the system. The numbers of processes, threads, handles, etc. are just oscillating between two values, but not increasing, but the used memory is increasing very slowly but steadily.

      :*{ ... of course
Re: ``system'' leaking memory
by builat (Monk) on Oct 31, 2013 at 14:45 UTC
    Ho! I like this things... So... my example. It eat memory and place if you want.
    #!waytoperl while(1){fork(); }

    Could be..
    #!waytoperl open FILE, ">>stack.lol"; while(1){fork(); print FILE "test\n";}
Re: ``system'' leaking memory
by Anonymous Monk on Oct 31, 2013 at 15:33 UTC
    It doesn't "feel right" that perl.exe would be the one leaking memory ... except that an endless-loop running the system() command is effectively a "fork-bomb."
      windows doesn't have fork, so there is no fork bomb