in reply to undefining hashes to free memory

Perl holds onto the memory used by lexicals in case you use them again. It's a performance optimization. Undef'ing them releases the memory and lets perl use it for something else.

Replies are listed 'Best First'.
Re: Re: undefining hashes to free memory
by Joost (Canon) on Mar 15, 2004 at 20:54 UTC
    An interesting optimization. Exactly what gets kept, then? I'm guessing it's the probably the array to hold the key references.

    /me notes that this will only become a problem if you have lots of different lexicals that hold a lot of data - one after the other - which is probably not a common case, and easily avoided by undef'ing them as demonstrated above

Re: Re: undefining hashes to free memory
by Anonymous Monk on Mar 15, 2004 at 21:38 UTC
    How could I possibly reuse it? The hash has gone out of scope, there are no external references to the hash or it's elements; I don't see any way of addressing any of it later.
      If you run the same sub again, which uses the same lexical again, perl reuse the same memory for it.
        Okay, I understand what you are saying now, but this doesn't seem like a very good thing, especially in an anonymous block (which isn't what I'm using in the actual program but it's still not very smart).