免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4138 | 回复: 3
打印 上一主题 下一主题

Perl 如何释放读取的xml文件内存(XML:Simple模块)? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-22 00:39 |只看该作者 |倒序浏览
本帖最后由 brant_chen 于 2010-08-22 00:42 编辑

我用的是XML::Simple。

我发现,我用(xml文件有2MB左右)

$xml_file_content = XMLin($xml_name);

后,内存涨了很多,我就把要读的内容存到一个hash后,然后置
$xml_file_content = undef;
sleep 10; # 留点时间观察内存释放没有
结果发现内存灭有释放呢?
请问怎么释放啊?
谢谢!
  1. #!/usr/bin/perl
  2. use XML::Simple;
  3. use Data::Dumper;

  4. my %table;
  5. my $xml_file1="I18n.tst";
  6. my $xml_file2="I18n2.tst";
  7. my $xml_name="List.xml";
  8. my $xml_file_content=undef;

  9. $xml_file_content = XMLin($xml_name);

  10. $table{$xml_file1}=[] unless exists $table{$xml_file1};
  11. $table{$xml_file2}=[] unless exists $table{$xml_file2};

  12. foreach my $key (keys (%{$xml_file_content->{$xml_file1}->{'en_iso-8859-1'}})){
  13.    print "test1:$key". "\n";
  14.    print "test12:$xml_file_content->{$xml_file1}->{'en_iso-8859-1'}->{$key}\n";   
  15.    push @{$table{$xml_file1}}, "[".$key."]".$xml_file_content->{$xml_file1}->{'en_iso-8859-1'}->{$key};
  16. }

  17. foreach my $key (keys (%{$xml_file_content->{$xml_file2}->{'en_iso-8859-1'}})){
  18.    print "test2:$key". "\n";
  19.    print "test22:$xml_file_content->{$xml_file2}->{'en_iso-8859-1'}->{$key}\n";   
  20.    push @{$table{$xml_file2}}, "[".$key."]".$xml_file_content->{$xml_file2}->{'en_iso-8859-1'}->{$key};
  21. }

  22. $xml_file_content=undef;

  23. foreach $xml_file (sort keys %table) {
  24.   print "\n$xml_file:\n";
  25.   my @cities = @{$table{$xml_file}};
  26.   print "test3:" . join ', ', sort @cities;
  27.   print ".\n";
  28. }
  29. sleep 10;
  30. exit 0;
复制代码

论坛徽章:
0
2 [报告]
发表于 2010-08-22 01:16 |只看该作者
因为存在$xml_file_content的引用··所以··没释放··除非你自己undef···

论坛徽章:
0
3 [报告]
发表于 2010-08-22 10:51 |只看该作者
有两个疑问:
1. 貌似我上面是遍历xml_file的值,然后进行赋值到我自己的%table里面的数组的。为什么是引用呢?
2. 请问如何自己undef呢?

非常感谢!

论坛徽章:
0
4 [报告]
发表于 2010-08-22 11:10 |只看该作者
有两个疑问:
1. 貌似我上面是遍历xml_file的值,然后进行赋值到我自己的%table里面的数组的。为什么是引用 ...
brant_chen 发表于 2010-08-22 10:51


你可以看一下perl的回收机制嘛·····
要undef的话 直接 undef $xml_file_content
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP