Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Timing of garbage collection

by BrowserUk (Patriarch)
on Jan 19, 2013 at 00:41 UTC ( [id://1014157]=note: print w/replies, xml ) Need Help??


in reply to Re: Timing of garbage collection
in thread Timing of garbage collection

Perl doesn't have "garbage collection" in the sense that it never gives memory back to the OS.

That's demonstrably not exactly true:

C:\test>perl -E"say `tasklist|find \"$$\"`; $x=chr(0); $x x= 2e6; say +`tasklist|find \"$$\"`; undef $x; say `tasklist|find \"$$\"`" perl.exe 139252 Console 1 4 +,660 K perl.exe 139252 Console 1 6 +,680 K perl.exe 139252 Console 1 4 +,724 K

That shows that perl allocating a 2MB scalar and then returning that 2MB back to the OS.

On my Perl/system, the break point for the size of allocations that are released back to the system is 1040351 bytes. anything more and it is; less and it is not:

C:\test>perl -E"say `tasklist|find \"$$\"`; $x=chr(0); $x x= 1040352; +say `tasklist|find \"$$\"`; undef $x; say `tasklist|find \"$$\"`" perl.exe 129340 Console 1 4 +,688 K perl.exe 129340 Console 1 5 +,788 K perl.exe 129340 Console 1 4 +,780 K C:\test>perl -E"say `tasklist|find \"$$\"`; $x=chr(0); $x x= 1040351; +say `tasklist|find \"$$\"`; undef $x; say `tasklist|find \"$$\"`" perl.exe 241476 Console 1 4 +,704 K perl.exe 241476 Console 1 5 +,788 K perl.exe 241476 Console 1 5 +,792 K

That number is a around 8k less than 1MB, so presumably it is 1MB internally but then some is used for internal management.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: Timing of garbage collection
by Marshall (Canon) on Jan 19, 2013 at 05:07 UTC
    What version of Perl are you running? I am still on Ver 5.10.1 with Active State.

      It doesn't depend on Perl version, it depends on malloc implementation.

        Under Debian Linux the real memory was returned to the system, but under AIX 5.2, the real memory increased after the 'undef $x;'. I used

        `ps -o "rssize" -p $$`

        to determine the real memory used. So it looks like it is system dependent code as zwon pointed out.

        "Well done is better than well said." - Benjamin Franklin

      Those tests were run using that exact same combination:

      C:\test>perl -v This is perl, v5.10.1 built for MSWin32-x64-multi-thread (with 2 registered patches, see perl -V for more detail) Copyright 1987-2009, Larry Wall Binary build 1007 [291969] provided by ActiveState http://www.ActiveSt +ate.com Built Jan 27 2010 14:12:21

      But the same has been true for every build since at least 5.8.1 and probably earlier, and continues through 5.16.1:

      C:\test>perl -v This is perl 5, version 16, subversion 1 (v5.16.1) built for MSWin32-x +64-multi-thread (with 1 registered patch, see perl -V for more detail) ... C:\test>perl -E"say `tasklist|find \"$$\"`; $x=chr(0); $x x= 1040351; +say `tasklist|find \"$$\"`; undef $x; say `tasklist|find \"$$\"`" perl.exe 17672 Console 1 4 +,992 K perl.exe 17672 Console 1 6 +,080 K perl.exe 17672 Console 1 6 +,084 K C:\test>perl -E"say `tasklist|find \"$$\"`; $x=chr(0); $x x= 1040352; +say `tasklist|find \"$$\"`; undef $x; say `tasklist|find \"$$\"`" perl.exe 270080 Console 1 4 +,912 K perl.exe 270080 Console 1 6 +,016 K perl.exe 270080 Console 1 5 +,012 K

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I think that it is fair to say that "mileage varies" even in this simple test....

        In a running application, things get more complicated than just "give me a MB" and then immediately I give you back a MB. Over time memory typically becomes more and more fragmented and it becomes more difficult to give back a "useable chunk" of memory...mileage does vary. And this does depend upon the malloc() that is being used. And of course the code.

        My original statement was not completely accurate. Sorry about that.

        C:perl -E"say `tasklist|find \"$$\"`; $x=chr(0); $x x= 1040352; say ` +tasklist|find \"$$\"`; undef $x; say `tasklist|find \"$$\"`" perl.exe 2208 Console 0 2,556 K perl.exe 2208 Console 0 3,600 K perl.exe 2208 Console 0 2,584 K C:perl -E"say `tasklist|find \"$$\"`; $x=chr(0); $x x= 1040352; say ` +tasklist|find \"$$\"`; undef $x; say `tasklist|find \"$$\"`" perl.exe 576 Console 0 2,552 K perl.exe 576 Console 0 3,592 K perl.exe 576 Console 0 2,576 K C:perl -E"say `tasklist|find \"$$\"`; $x=chr(0); $x x= 1040352; say ` +tasklist|find \"$$\"`; undef $x; say `tasklist|find \"$$\"`" perl.exe 5712 Console 0 2,556 K perl.exe 5712 Console 0 3,600 K perl.exe 5712 Console 0 2,584 K C:perl -E"say `tasklist|find \"$$\"`; $x=chr(0); $x x= 1040352; say ` +tasklist|find \"$$\"`; undef $x; say `ta sklist|find \"$$\"`" perl.exe 5468 Console 0 2,552 K perl.exe 5468 Console 0 3,596 K perl.exe 5468 Console 0 2,580 K

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found