Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Perl: Общие вопросы > задачка с очисткой переменной и форками


Автор: DooZ 8.6.2007, 10:52
титл сообщения изменить не могу

вообщем изменил вопрос
вот код:

Код

#!/usr/bin/perl -w

my %hash;

print "s0\n";
sleep(5);  #смотрим top в линуксах, памяти жрет 0.0%

open(F, "file.txt");   #файл этак метров на 20 например

    while (<F>)
    {
    $hash{$_}++;
    }

close(F);

print "s1\n";
sleep(5);   #смотрим top памяти хавает уже 0.9 - 1.1 зависит от файла
%hash=();   #очищаем ????
print "s2\n";
sleep;    #смотрим top а памяти жрется все теже 0.9 - 1.1% что за бред???




где затыка? что не так???

Автор: JAPH 8.6.2007, 16:47
Судя по `perldoc -f keys`, попробуйте
Код
undef %hash;

Автор: DooZ 11.6.2007, 07:50
яж написал что пробывал
уже разобрался
встроенная очистка перла не очищает хеш храня его на будущее, вдруг понадобится

вот что пишут:
Perl will save the old memory for reuse, and the new hash will use that left over memory. If you make the hash a global, and "clean it out", it will reuse the same mem over and over, and memory usage will rise to the "peak" level of the biggest hash. Perl (and almost any other program) will not release memory back to the OS.... it figures if you used it once, you may need it again, so it holds on to it. If you want to release the mem back to the OS, use C (which will allow you to deallocate the mem), or "fork and exec" the subroutine, and mem will be truly released at the end of the exec.

так что приходится юзать DBM что бы не тратить память...

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)