in reply to Re: Memory Usage of Perl System command
in thread Memory Usage of Perl System command

the thing is even if you run any command other than adb devices using system command, I am seeing the same memory increase. for example: replacing
system("adb devices");
with
system("dir"); ## just an example, you can replace it with any comm +and
the output looks like this:
########## memory usage of perl start of execution ########### perl.exe 17304 RDP-Tcp#0 1 9,536 K ############################################################## ########## memory usage of perl end of execution ########### perl.exe 17304 RDP-Tcp#0 1 68,372 K ##############################################################
My question was how can we release the memory allocated by the system command? I understand that perl doesn't release the memory back to OS but it should re-use the memory rather than allocating new memory block for each call, isn't that right?

Replies are listed 'Best First'.
Re^3: Memory Usage of Perl System command
by Laurent_R (Canon) on Jan 09, 2016 at 00:27 UTC
    And what do you get if you run the exact same thing, but just iterating once, 10 times, 100 times and perhaps 1,000 times, instead of 5,000 times on your system call?

    My gut-feeling idea is that the number of times you run your command is probably irrelevant to a large extent. Which would mean that you have a memory penalty for the first system call, but not really for the others, so that the memory usage would appear to be mostly reclaimed by the Perl process between the various calls. But that's only a guess, I don't really know and can't run the exact same tests. But relatively similar tests lead me to think that's probably what you will experience.

      as per your suggestion, I changed the code to get the memory usage for each iteration as shown below:

      ############################################################## ########## memory usage of perl start of execution for iter: 0 ####### +#### perl.exe 18124 RDP-Tcp#0 1 9,544 K ############################################################## ########## memory usage of perl end of execution for iter: 0 ######## +### perl.exe 18124 RDP-Tcp#0 1 9,580 K ############################################################## iteration Completed : 0 ########## memory usage of perl start of execution for iter: 1 ####### +#### perl.exe 18124 RDP-Tcp#0 1 9,588 K ############################################################## ########## memory usage of perl end of execution for iter: 1 ######## +### perl.exe 18124 RDP-Tcp#0 1 9,624 K ############################################################## iteration Completed : 1 ########## memory usage of perl start of execution for iter: 2 ####### +#### perl.exe 18124 RDP-Tcp#0 1 9,640 K ############################################################## ########## memory usage of perl end of execution for iter: 2 ######## +### perl.exe 18124 RDP-Tcp#0 1 9,668 K ############################################################## iteration Completed : 2
      after 40 iterations memory has been increased as shown below:
      ########## memory usage of perl start of execution for iter: 45 ###### +##### perl.exe 18124 RDP-Tcp#0 1 11,308 K ############################################################## ########## memory usage of perl end of execution for iter: 45 ####### +#### perl.exe 18124 RDP-Tcp#0 1 11,324 K ############################################################## iteration Completed : 45 ########## memory usage of perl start of execution for iter: 46 ###### +##### perl.exe 18124 RDP-Tcp#0 1 11,332 K ############################################################## ########## memory usage of perl end of execution for iter: 46 ####### +#### perl.exe 18124 RDP-Tcp#0 1 11,348 K ############################################################## iteration Completed : 46 ########## memory usage of perl start of execution for iter: 47 ###### +##### perl.exe 18124 RDP-Tcp#0 1 11,356 K ############################################################## ########## memory usage of perl end of execution for iter: 47 ####### +#### perl.exe 18124 RDP-Tcp#0 1 11,368 K ############################################################## iteration Completed : 47 ########## memory usage of perl start of execution for iter: 48 ###### +##### perl.exe 18124 RDP-Tcp#0 1 11,376 K ############################################################## ########## memory usage of perl end of execution for iter: 48 ####### +#### perl.exe 18124 RDP-Tcp#0 1 11,392 K ############################################################## iteration Completed : 48 ########## memory usage of perl start of execution for iter: 49 ###### +##### perl.exe 18124 RDP-Tcp#0 1 11,404 K ############################################################## ########## memory usage of perl end of execution for iter: 49 ####### +#### perl.exe 18124 RDP-Tcp#0 1 11,504 K ############################################################## iteration Completed : 49 ########## memory usage of perl end of execution ########### perl.exe 18124 RDP-Tcp#0 1 11,512 K ##############################################################
      BTW as mentioned by Mr.Muskrat, I tried the script on linux station and the issue is not seen.

Re^3: Memory Usage of Perl System command
by Mr. Muskrat (Canon) on Jan 08, 2016 at 23:47 UTC

    I guess I should have tried to run it before commenting. I assumed it was adb devices doing it.

    BTW, I can't reproduce the problem on Linux.

      Unfortunately, I need to run it on windows PC only. Is there a better alternative for executing the commands? I tried backticks/exec/ but seeing the same issue even with those.