profile picture

Memory leaks

October 08, 2012 - programming perl memory

Spent the whole day looking for sources of memory leaks. One of them was because I decided to use named captures. It so happened that perl leaks some memory if named capture doesn't match. Here's an example:

use 5.010;
use strict;
use warnings;
say `ps vp $$`;
for (1..1_000_000) {
    "08-Oct-2012" =~ /^(?'date'\d\d-\w\w\w-\d\d\d\d)(?: (?'time'\d\d:\d\d))?/;
    say "Time: $+{time}" if $+{time} and 0;
say `ps vp $$`;

Funnily, if you replace "08-Oct-2012" with "08-Oct-2012 22:17" it will stop leaking. I can reproduce the problem with 5.10.1 and 5.14.2. It was fixed in 5.16.0, but at the work we are using Debian with system perl, so have to wait around 2.5 years before fix will make it into stable and we will be able to start using named captures.

Another one was in ZMQ::LibZMQ2 library:, so I had some fun fixing XS code. Fixed version is already available from CPAN.