http://www.perlmonks.org?node_id=1010586


in reply to Avoiding memory loss...

Hi

first, you don't need to intialize an array, perl does the allocation automatically when you do the push.

#if (! exists $cTable{$cID}{raw}) { # $cTable{$cID}{raw}=[]; #} push @{$Table{$cID}{raw}}, $currentVal;

> and, periodically wanting to delete the hash.

delete $cTable{$cID}
> My question is, do I first need to do something to remove the array or is that cleaned up automatically for me?

depends, garbage collections cleans up variables with an empty reference count.

so as long as you don't have any $copies = $Table{$cID} somewhere else in the code the hash will be automatically destroyed when deleting the last reference.

The same for all nested substructures/elements like the array $Table{$cID}{raw}, if there are no other references they will be destroyed, too.

in other words: no reference left <=> no memory used

for details see: perlref

Cheers Rolf