in reply to Re^2: Release memory in hash of hashes
in thread Release memory in hash of hashes
You can let scope do this for you:
{ my $word_index_ref = retrieve( $word_index_file ); # Use $word_index_ref here } # $word_index_ref is out of scope here
When the block (scope) in which lexical variable $word_index_ref is declared is exited, the variable goes out of scope and, if there are no remaining references, associated memory is freed. This is one reason for using lexical variables and declaring them in the smallest possible scope. Sometimes an appropriate scope already exists (e.g. the blocks of subroutines, loops and conditionals), but you can create one anywhere.
|
|---|