#!/usr/bin/env perl use strict; use warnings; use 5.022; # WARNING! Will consume about 3GB of RAM $| = 1; my $size = 1024 * 1024 * 1000; my $s = 'C' x $size; # eval << 'EOD'; $s =~ s/C/1/; # copy of CCCCC... will stay in memory $s =~ s/C/2/; # same but 1CCCC... # EOD print "Time to measure memory usage...\n"; sleep(9000); #### #!/usr/bin/env perl use strict; use warnings; use 5.020; my $size = 8; my $s = 'C' x $size; use Test::LeakTrace; leaktrace{ $s =~ s/C/1/; $s =~ s/C/2/; } -verbose; #### leaked SCALAR(0x108fb20) from 3GB_OOM.pl line 14. 13:leaktrace{ 14: $s =~ s/C/1/; 15: $s =~ s/C/2/; SV = PV(0x1042f30) at 0x108fb20 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x1081e50 "CCCCCCCC"\0 CUR = 8 LEN = 10 COW_REFCNT = 1 leaked SCALAR(0x108f9e8) from 3GB_OOM.pl line 15. 14: $s =~ s/C/1/; 15: $s =~ s/C/2/; 16:} -verbose; SV = PV(0x10c7ab0) at 0x108f9e8 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x10ab1f0 "1CCCCCCC"\0 CUR = 8 LEN = 16 COW_REFCNT = 0