SPUG: Question for somebody

Tim Maher/CONSULTIX tim at consultix-inc.com
Thu Nov 2 21:25:16 CST 2000

On Thu, Nov 02, 2000 at 06:18:20PM -0800, Richard Anderson wrote:
> This in not correct - memory is freed by Perl's garbage collection algorithm
> when a lexically scoped variable goes out of scope, unless there is a
> pathological circular reference situation.

The question is what is meant by "freed"; the UNIX (malloc/free) model
is that the memory is marked as available for reuse by the process, but
not relinquished to the OS until the program exits.  This is justified
by the assumption that if memory were really to be relinquished (by
diminishing the size of the data segment through brk() or sbrk()) the
program might just need it again later anyway, and have to call malloc()
once more to get it.

I'm not an expert on Perl internals, but I've gotten the impression from
some who know more about it than I do that Perl's memory management model
is based on this (perfectly sensible, tried and true) UNIX model.

> If Perl really did not return the memory to the OS until the program exited,
> recursive subroutines would be impossible in Perl.

Huh?  I don't follow your logic here.  Typical C programs don't really
relinquish memory until they exit (because most C programmers only call
free(), and have never even heard of brk()), and recursion is certainly
not uncommon, let alone impossible, in C.

| Dr. Tim Maher, CEO, Consultix       (206) 781-UNIX/8649;  ask for FAX# | 
| Email: tim at consultix-inc.com        Web: http://www.consultix-inc.com  |
|Training- TIM MAHER: Unix, Perl  DAMIAN CONWAY: Adv. Perl, OOP, Parsing |
|CLASSES: 12/5-8: Basic UNIX   *Coming in 2000: Database Prog. with Perl |

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/

More information about the spug-list mailing list