Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I know..I know, why am I trying to manage memory when there's a garbage collector to do that for me. I'm simply trying to stay off of the performance radar by keeping my stack size low by invoking gc after re-initializing an array.
  • Comment on Is there a way to invoke perl's garbage collector?

Replies are listed 'Best First'.
Re: Is there a way to invoke perl's garbage collector?
by ikegami (Patriarch) on Mar 07, 2006 at 19:40 UTC

    Perl uses reference counting, not garbage collection. Everything is freed as soon as there is no reference to it.

    Any memory freed by Perl might not be returned to the OS, but it will become available to Perl for reuse.

    Update: For example,

    print("Check size of process $$ and press ENTER."); # 1676K <STDIN>; $a .= ' ' for 1..100_000; print("Check size of process $$ and press ENTER."); # 1920K <STDIN>; undef $a; $a .= '!' for 1..100_000; print("Check size of process $$ and press ENTER."); # 1920K <STDIN>;
      Thanks. I understand that the memory is available for use by perl, otherwise it would push the stack past 256MB (size of a segment or PTHREAD_STACK_MAX) which in my case is causing perl to core when creating a DOM in XML::LibXML. I'm having to limit the amount of raw xml I convert to a DOM tree to avoid this, but I'd like to reduce my in_use pages during proccessing if at all possible and that won't happen if perl does not truly free the memory. Thoughts?
Re: Is there a way to invoke perl's garbage collector?
by revdiablo (Prior) on Mar 07, 2006 at 20:22 UTC