<p>Does a hash shrink in Perl as you delete elements. </p>

<p>More specifically I had a perl program that I inherited that would parse a huge file ( 1 GB ) and load up a hash of hashes. it would do that same for another file and then do a comparison of different elements. The memory consumption was huge during this process and even though I added deleting hash elements has they were used the memory consumption seemed to be unaffected.</p>

<p>The script was extremely slow and such a memory hog. I know it was not well designed but any ideas about the hash memory usage?</p>

In general, Perl cannot return memory to the operating system. It may be able to reuse memory internally, though, which could reduce the amount of memory needed by a program.
See perlfaq3:
How can I free an array or hash so my program shrinks?
If the memory used by the hashes is excessive (i.e. > physical memory) you could
```
tie
```
them to a file on disk. This would greatly reduce your memory usage but be warned that accessing a structure on disk is much slower than accessing one in memory. (So is disk thrashing.)