in reply to Garbage Collection on Hash delete

Everything of course depends on what you mean by free the memory.

PERL will not release any memory back to the operating system as long as the script runs.

Of course if you are careful in using variables (esp. hashes and arrays) and "release" them one way or another as soon as they have served their purpose, PERL will not have to needlessly allocate additional memory for itself.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re: Re: Garbage Collection on Hash delete
by Elian (Parson) on Jan 13, 2003 at 02:58 UTC
    Perl will release memory back to your C runtime library. Depending on what that is, memory may well get released back to the system. This has worked for years on VMS and MacOS, and reasonably recent versions of glibc will also release memory in some circumstances back to the system.

      Well I have to work within a Windows environment and use pre-compiled versions of PERL, so I don't know if my version of PERL (Activestate) is bright enough to release memory back to the pool.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        Windows is generally clever enough to reclaim unused space. Unused space will only get returned if an entire chunk is empty, though, which may not happen. Often a big allocation will be carved into several pieces, and if even one of those pieces isn't empty the memory won't get returned.
Re: Re: Garbage Collection on Hash delete
by netoli (Initiate) on Jan 12, 2003 at 13:04 UTC
    CountZero got the point
    =>PERL will not release any memory back to the operating system as long as the script runs
    My script is should run forever and that's why I cannot just terminate the programm or go out of a block.
    Will Perl release the memory if delete is used ?
    netoli
      So long as you don't use excessive amounts of memory, it shouldn't be a problem. Any way you clear the hash, the memory will be returned to Perl's pool. Even though Perl doesn't give any of its pool back to the OS, it will recycle memory from the pool for later use in the script. So if you accumulate a lot of data in the hash, the Perl process will grow by (say) 1MB, and not shrink again even if you clear the hash. However, if you fill the hash again, the Perl process will not grow again - it will simply reuse the memory it had allocated before.

      Makeshifts last the longest.