• Garbage collection

    From David Noon@2:257/609.5 to Mike Luther on Thursday, February 22, 2001 01:02:10
    Hi Mike,

    Replying to a message of Murray Lesser to Mike Luther:

    The "ml" quote is from Mike Luther, the "ML" quote is from Murray Lesser.

    Does PL/I have automatic garbage collection? Is the fact
    >> that you don't consider PL/I to be a "modern" language, the
    >> reason you didn't include it?

    To my knowledge, PL/I does not have automatic garbage collection. AFAIK, no language that requires a "FREE" (or equivalent) statement
    to recover memory otherwise lost in "the heap" has automatic garbage collection. I've never written a program (except in C) that required
    a "free" statement, so I really don't know.

    Murray has given you the complete answer here, but phrased somewhat obliquely. ... :-)

    PL/I garbage collection varies with "storage class". Variables in virtual memory are each allocated in one of 4 storage classes: STATIC, AUTOMATIC, CONTROLLED and BASED. The garbage collection varies with each.

    Under STATIC allocation the variables exist for the entire life of the program's execution and garbage collection is neither required nor possible.

    Under AUTOMATIC allocation [the usual default] the variables are constrained by
    their "scope", and once they go out of scope they are *freed automatically*.

    Under CONTROLLED allocation the variables come into existence and go out of existence based on explicit program statements. Not only must these variables be declared, but they must be explicitly allocated and freed.

    Variables in the BASED class are pointer located. They can be heap-allocated, like controlled variables, or their pointers can simply be set to the address of of some other variable and they become aliases for those other storage locations. In the first case the program should free the memory explicitly; in the second case the original allocation's garbage collection procedure should be followed.

    If you keep things simple -- specifically, stick to AUTOMATIC and STATIC variables -- then your garbage will be collected automatically. You need only consider garbage collection when you move to more exotic memory allocation schemes.

    Basically, what Murray has said is that he sticks to AUTOMATIC and STATIC allocation and so never needs to code explicit garbage collection.


    <Team PL/I>

    --- FleetStreet 1.25.1
    * Origin: My other computer is an IBM S/390 (2:257/609.5)