in reply to Possibly silly perl memory allocation question, duplicating scalars

Most ops have a target, an invisible lexical that stores their result. "a" x 5_000_000 is initially stored in this target (bound to that x operation), then assigned (copied) into $x. For some operations of form $lexical = expr1 op expr2 the op target is diverted onto $lexical and the assignment is optimized away, but the repeat (x) op isn't one of those; don't know why.

Targets stay allocated for as long as their code is around (in the theory that next time the op is used, space for its result needn't be allocated again); the only easy way to reclaim their memory is to remove all references to the code they are in.

  • Comment on Re: Possibly silly perl memory allocation question, duplicating scalars