in reply to Perl memory leak?

Scary...
perl -e "while (1){@X=split/:/,'1::'}"
Slurps 170MB of RAM in about 3 seconds on my NT box...
I'm not that good with Perl internals; however, the default behavior of split() is to ignore trailing empty fields. I'm thinking Perl takes the "ignoring" to the next level and "forgets" to release the memory; If you do
perl -e "while (1){@X=split/:/,'1::',-1}"
then everything works as expected. "-1" tells split() to treat trailing empty fields as valid; i.e., not to ignore them.

--perlplexer

Replies are listed 'Best First'.
Re: Re: Perl memory leak?
by perlplexer (Hermit) on Apr 17, 2002 at 18:36 UTC
    Hmm... or maybe not... :)
    my()ing the @X seems to fix it as well.
    perl -e "while (1){my @X=split/:/,'1::'}"
    (use strict;)++

    --perlplexer

    Update:added "my"
      my()ing @X outside the while works as well...

      perl -e'my@X;while(){@X=split/:/,"1::"}'
      good catch, perlplexer.

      ~Particle ;Þ

Re: Re: Perl memory leak?
by jsprat (Curate) on Apr 18, 2002 at 01:32 UTC
    Try

    perl -MO=Deparse -e "while (1){@X=split/:/,'1::',-1}"

    Crashes perl on my W2K and my NT sp6 boxes! Windows tells me an error log is being created, but no log is created.

    Update:

    Wed 04/17/2002 18:43:53.45 C:\>perl -MO=Deparse -e "@X=split /:/,'1::'"

    Take away the loop, still crashes.
    Wed 04/17/2002 18:43:43.28 C:\>perl -MO=Deparse -e "@X=split /p/,'1pp'"

    s/:/p/, still crashes. Take away the @X, works fine.
    Has a bug report been submitted?