如何在Perl中释放内存? [英] How to free memory in Perl?

查看:254
本文介绍了如何在Perl中释放内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下所示:

  my%var; 
my%var_new = {}; (1){
while(my($ k,$ v)= each%var){
& a_sub($ v);


}
%var = {}; #A
map {$ var {$ _} = $ var_new {$ _}; }键%var_new;
%var_new = {}; #B
}

sub a_sub {#....}#将填充%var_new

我的程序的内存使用量增加了。



看起来Perl并没有在A行和B行释放内存。



如何手动让Perl释放内存%var %var_new

的过程。在可能的情况下,Perl会重新使用它已经分配的内存,而不是向操作系统要求更多,但是你不会看到进程使用的内存减少。


My code looks like:

 my %var;
 my %var_new={};

 while(1){
     while(my ($k,$v)=each %var){
            &a_sub($v);
     }
     %var={}; # A
     map { $var{$_}=$var_new{$_}; } keys %var_new;
     %var_new={}; # B
 }

 sub a_sub { #....} # will fill %var_new

My program's memory usage goes up and up.

It seems Perl doesn't free memory at Line A and Line B.

How can I manually make Perl to free up memory used %var and %var_new?

解决方案

IIRC, once Perl has allocated memory from the operating system, it holds onto that memory for the life of the process. Where possible, Perl will reuse memory it has already allocated rather than ask the operating system for more, but you won't see the memory used by a process decrease.

这篇关于如何在Perl中释放内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆