Recently, we have been struggling with the issue of how to release memory in Perl. Below are a few simple statements:
1. Perl-e 'for $ I (1 .. 10000) {$ hash {$ I} = 0; print "$ I \ t $ hash {$ I} \ n"; Delete $ hash {$ I };} for $ J (10001 .. 20000) {$ hash {$ J} = 1; print "$ J \ t $ hash {$ J} \ n "}'
2. Perl-e 'for $ I (1 .. 10000) {$ hash {$ I} = 0; print "$ I \ t $ hash {$ I} \ n"; UNDEF $ hash {$ I };} for $ J (10001 .. 20000) {$ hash {$ J} = 1; print "$ J \ t $ hash {$ J} \ n "}'
3. Perl-e 'for $ I (1 .. 10000) {$ A [$ I] = 0; print "$ I \ t $ A [$ I]"; Delete $ A [$ I];} for $ J (10001 .. 20000) {$ A [$ J] = 1; print "$ J \ t $ A [$ J] \ n ";}'
4. Perl-e 'for $ I (1 .. 10000) {$ A [$ I] = 0; print "$ I \ t $ A [$ I]"; UNDEF $ A [$ I];} for $ J (10001 .. 20000) {$ A [$ J] = 1; print "$ J \ t $ A [$ J] \ n ";}'
After the hash and elements in the array are deleted or initialized, the occupied memory is not released.
Data: dumper:
Use Data: dumper;
% Disney = ('cat' => 'Tom ', 'mouse' => 'Jerry ', dog => 'goofie ');
Delete $ Disney {'cat '};
$ Disney {'Dog'} = '';
Print dumper (\ % Disney );
In this way, the memory can be released after all data is read.