Loading ...
Sorry, an error occurred while loading the content.

Re: strange memory-problem

Expand Messages
  • peter pilsl
    ... Thnx to all for your reply. On my linux-machines perl releases the memory in many cases immediately. If I create big strings and undef them then the memory
    Message 1 of 4 , Apr 14 10:46 AM
    • 0 Attachment
      Quoting Perrin Harkins <perrin@...>:

      >
      > In addition, I believe that on most OSes no process ever releases
      > memory. Once it has been used by that process, it stays used. It may
      > be paged out though if it becomes inactive.
      >

      Thnx to all for your reply. On my linux-machines perl releases the memory in
      many cases immediately. If I create big strings and undef them then the memory
      is released immediately.

      As example I'd like to quote a script I recently posted to comp.lang.perl.misc
      after discovering that my problem is not mod_perl related. The script uses big
      memory in three ways:
      way1 : a big empty array
      way2 : a big filled array
      way3 : a big string

      In way1 and way2 the memory is released immediately upon DESTROY and no way to
      get back the mem of way2 :)


      thnx,
      peter


      -------------mem.pl---------------
      #!/usr/bin/perl -w

      use strict;

      package test;

      sub new{
      my $class=shift;
      my $s={};
      bless($s,$class);
      my $way=shift;

      if ($way eq '1') {
      $s->{bigarray}=[];
      $#{$s->{bigarray}}=5000000;
      }

      if ($way eq '2') {
      foreach my $row (0..300000) {
      $s->{ref}->[$row]=$row.'-'.'0123456789012345678901234567890123456789';
      }
      }

      if ($way eq '3') {
      foreach my $row (0..300000) {
      $s->{string}.=$row.'-'.'0123456789012345678901234567890123456789';
      }
      }

      return $s;
      }

      #sub DESTROY{warn "DESTROY"}

      package main;

      print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
      my $s=test->new(1); print "1\n";
      print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
      undef $s;
      print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
      $s=test->new(2); print "2\n";
      print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
      undef $s;
      print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
      $s=test->new(3); print "3\n";
      print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
      undef $s;
      print `ps waux | grep mem.pl | grep -v grep | grep -v emacs`;
      -------------------------------------------------

      a output would be, where mem is released after 1 and after 3 but not after
      2 !! (mem is 5th col of output and name of the script is not printed here
      to fit the line :)

      $ ./mem.pl
      pilsl 1568 0.0 0.3 2860 1308 pts/6 S 23:16 0:00
      1
      pilsl 1568 0.0 5.4 22396 20856 pts/6 S 23:16 0:00
      pilsl 1568 37.0 0.3 2864 1328 pts/6 S 23:16 0:00
      2
      pilsl 1568 80.5 7.1 29040 27504 pts/6 S 23:16 0:01
      pilsl 1568 77.6 6.6 26992 25456 pts/6 S 23:16 0:02
      3
      pilsl 1568 85.0 10.1 40656 39124 pts/6 S 23:16 0:03
      pilsl 1568 85.0 6.6 26992 25460 pts/6 S 23:16 0:03
    Your message has been successfully submitted and would be delivered to recipients shortly.