Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am loading a hash with some one lakh of data in my program, do i need to release the memory after the program? Thanks,

Replies are listed 'Best First'.
Re: Release hash memory
by cdarke (Prior) on Jul 13, 2009 at 13:14 UTC
    Interesting that you use the word program instead of process. Is this intentional? On POSIX system, a program can be replaced within the same process using the exec family of functions (Microsoft Windows does not have this feature). These functions replace the text, data, heap, and stack segments, so ordinary perl variables will be destroyed. Some areas of memory are retained between programs within the same process. These include file descriptors and the environment block, so avoid unnecessary environment variables, and close all files before an exec.
Re: Release hash memory
by Marshall (Canon) on Jul 13, 2009 at 12:22 UTC
    I don't know that a "lakh" of data is! I will say that once Perl gains a "lakh" or kilobyte or whatever from the O/S, it will never give it back. Perl will and can reuse this memory for its own purposes. The virtual memory "footprint" of a Perl process never gets smaller.

    One of the powers of Perl is that it does the memory management for you! So in general you have no worries! Forget it (or until you get into advanced applications).

    The O/S will free all memory used by an application when it ends. That is true in Java, C, Perl, etc. There is some very complex stuff about memory management, but if you are dealing with "lakh"'s I don't think you have to worry.

    Update: don't worry: Make some hash and when your program ends that memory will be freed.

      I think he meant lakh

      PS. I'm not OP.
        Great! Learned something about another unit of measurement, the lakh! The above advice is the same whether bytes, bits, lakhs, or whatever.

        Update: for those who are interested, a lakh is 100,000, http://en.wikipedia.org/wiki/Lakh

Re: Release hash memory
by Anonymous Monk on Jul 13, 2009 at 11:39 UTC
    No, when the program exits it releases memory
Re: Release hash memory
by si_lence (Deacon) on Jul 13, 2009 at 12:18 UTC
    As noted by Anonymous Monk above the memory is freed when the program exits.
    Why do you think a hash is different with respect to memory handling than other variables like a scalar or an array?
    Do you run into memory issues with your program?
    Just wondering

    cheers, si_lence