:On Sep 24, 2011, at 9:08 PM, "tchrist1 via RT" <perlbug-followup@perl.org> wrote: : :> I bet something is preallocating a capture SV :> that's the same size as the original string. :> :> --tom Matthew Horsfall <wolfsage@gmail.com> wrote: :That coincides with other tests that I've done - capture matching against the 8MB string causes an 8MB growth in memory the first fee times it's done. : :-- Matthew Horsfall (alh) I think the problem case is: my $string = 'x' x 1024; $string =~ /^(x)/; $string = 'y' x 1024; print $1; We copy the target string when we have captures, so that looking at the captures after the original target string has changed does not lead to segfaults or subtler badness. (Internally, the regexp engine uses only offsets within the string to mark possible matches; on a successful match we know the final offsets are the actual captures.) I don't remember if there was a specific reason we needed to copy the whole string rather than just the <min offset> to <max offset> substring. HugoThread Previous