The stupid question is the question not asked | |
PerlMonks |
Substitution with regex and memory consumptionby k-mx (Scribe) |
on Feb 29, 2020 at 11:01 UTC ( [id://11113568]=perlquestion: print w/replies, xml ) | Need Help?? |
k-mx has asked for the wisdom of the Perl Monks concerning the following question: Hello, comrades monks! I want to share knowledge about interesting regex behavior:
Every expression with substitution call, will copy original string and store it until next call. So, memory not leaking and will be reused (for e.g. inside loop blocks), but this behavior can lead to serious RAM consumption. The only known (for me) workaround for this problem is string eval, that will force memory reclaim, but this is clumsy in my opinion. What do you think about such behavior? Is there more elegant way to free up memory used by 's///'? UPD:Reproduced on 5.22.2 (Slackware 14.2), 5.30.0 (Centos 7), and no memory waste on 5.16.3 (Centos 7) Investigation with 'Test::LeakTrace'<Reveal this spoiler or all in this thread>
Interesting links:
Back to
Seekers of Perl Wisdom
|
|