if( opendir( DIR, $dir ) ) {
$self->{files}= [
map {
File::Spec->catfile( $dir, $_ );
} File::Spec->no_upwards( readdir(DIR) )
];
closedir DIR;
} else { ... {
At that point, when you assign a new arrayref to $self->{files}, the previous arrayref in that spot is overwritten and therefore its reference count is reduced - if that was the only reference to the previous arrayref, it will automatically be freed.
So, to free unneeded memory in perl all you need to do - all you should do - is precisely to remove all references to the data.
I suspect therefore that the problem is not where you think it is. I suggest that you step back and compose a new question - start off by telling us what makes you think you are leaking memory, and what in the process of tracking that down led you to believe the problem lay here.
Hugo |