Perl script weird behavior / memory recovery

My script does the following

  • Reads a huge text file and creates a hash from it. (About 24 million simple pairs of key values. It takes about 5 minutes and consumes 92% of the computerโ€™s memory 4 GB).
  • Starts a simulation using information from a hash. (takes about 30 minutes)
  • Prints the results at the end of the simulation (to file and standard output)

He then waits 10 + minutes after the last press statement and release. Waiting at the end does not happen every time. During the wait top command, the same 92% memory usage is displayed, but without using a processor. Why does this happen sometimes after its completion? If I hit Ctrl C , it will exit immediately without any changes in the results (s). How do I debug this or expected behavior since the hash is huge?

EDIT

Is it possible to recover memory on the fly by removing unnecessary key-value pairs from the hash?

+7
linux perl swap operating-system hash
source share
1 answer

I assume that you know the delete function (therefore the remote link to perldoc -f delete :)

You can use valgrind to debug memory. Also this hint may be useful: Perl v5.10.1 has a memory leak or how to interpret valgrind It suggests using:

use Perl :: Destruct :: Level level => 1;

+1
source share

All Articles