2 responses to “Python Variables”

  1. Deadpan110

    This seems perfectly logical to me as for instance (within PHP):
    $somevar = "abcde";

    The length of the string in bytes is a certain length and without using references, the following would happen:
    $somevar = "abcde";
    $somevar = "fghijklmn";
    echo $somevar;
    Output:
    fghij;

    The rest of the string would not fit into the same 'box' as the initially set variable.

    Things are more interesting when a variable is referenced within different scopes.

    Take the following example from PHP: unset - Manual:

    function foo()
    {
    static $bar;
    $bar++;
    echo "Before unset: $bar, ";
    unset($bar);
    $bar = 23;
    echo "after unset: $barn";
    }

    foo();
    foo();
    foo();
    Output:
    Before unset: 1, after unset: 23
    Before unset: 2, after unset: 23
    Before unset: 3, after unset: 23

    Which leads me to 'unset' (there are probably similar functions within all languages)

    Does un-setting a variable from all scopes leave empty holes in the programs memory?

    The places where the references were initially stored could no longer be accessible - or does the language runtime compiler have a garbage collection and recycle empty space?

    Read this comment on occupied memory that is rendered useless as you cannot reference it anymore which asks the same questions.

    BTW: nothing wrong with your GIMP skills :P

Leave a Reply