Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Timing of garbage collection

by Marshall (Prior)
on Jan 19, 2013 at 00:09 UTC ( #1014155=note: print w/ replies, xml ) Need Help??


in reply to Timing of garbage collection

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

Once Perl has memory from the OS, it has it forever.
A long-lived Perl app will reach a maximum memory usage and just stay at that number forever (provided no memory leaks).

If you un-define an object ref: $obj_a = undef;
Or say $obj_a = Method_X->new(...), reuse/reassign an object ref that has the same effect as long as no reference to an in internal structure within obj_a is in existence.

Perl has its own memory management and reuses memory when it can.


Comment on Re: Timing of garbage collection
Re^2: Timing of garbage collection
by BrowserUk (Pope) on Jan 19, 2013 at 00:41 UTC
    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.
      What version of Perl are you running? I am still on Ver 5.10.1 with Active State.

        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.

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

Re^2: Timing of garbage collection
by eyepopslikeamosquito (Canon) on Jan 19, 2013 at 01:17 UTC

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

    First, the statement is wrong, as already demonstrated by BrowserUk. Whether perl releases memory back to the OS or not depends simply on the implementation of malloc/realloc, as described at Re: Not able to release memory.

    Second, whether it returns memory to OS is not related to garbage collection! As already noted by dave_the_m, perl uses a reference-counted garbage collector, so you get "deterministic destructors" for free (i.e. in perl, you are guaranteed that an object is destroyed (and destructor called) immediately its reference count goes to zero). BTW, deterministic destructors are a feature of the C++ RAII idiom yet are problematic when using a mark-and-sweep garbage collector, such as that used by Java, which is why Java has a "finally" clause (see also Dispose pattern).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-07-25 00:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls