I have no doubt that you need these copies. But why do you expect that multiple copies would use the same amount of memory as a single structure? After each loop iteration your array contains one more element, so its size is bigger
use 5.010;
use strict;
use warnings;
use Devel::Size qw(total_size);
use Storable;
my %hash = ( a => 1, b => 2, c => 3);
say "Size of hash is: ", total_size(\%hash);
my $ref;
for (1..100_000) {
push @$ref, Storable::dclone(\%hash);
}
say "Size of array is: ", total_size($ref);
__END__
Size of hash is: 313
Size of array is: 31448769
|