if the memory allocated to the hash had not been passed by ref. to the array, would perl have released it's memory?
Yes. Perl uses reference counting to determine if a variable is still in use. As soon as there are no references to a variable, the memory is released back to Perl (but not necessarilly to the operating system).
For example,
{
# Creates a scalar with value 'val1'.
my $var1 = 'val1'; # 1 reference to val1.
}
# $var1 goes out of scope.
# 0 references to val1.
# No more references to 'val1', so it is released.
my $var2;
{
# Creates a scalar with value 'val1'.
my $var3 = 'val2'; # 1 reference to val2.
$var2 = \$var3; # 2 references to val2.
}
# $var3 goes out of scope.
# 1 reference to val2.
$var2 = 'val3' # 0 references to val2. 1 reference to val3.
# No more references to 'val2', so it is released.
|