Subject: | array retrieval leaks memory |
Hi,
DBD::Pg leaks memory when it's accessing PostgreSQL array values.
Creating the included table and running leak.t produces a constant and
sizeable memory leak for me.
When the placeholder is changed from 'foo' to 'bar', so that for the
given row the array is NULL, the leak stops and the program has constant
memory usage over time.
I've used 5.8.8 and the latest DBD::Pg version:
$ perl5.8.8 -MDBD::Pg -le 'print $DBD::Pg::VERSION'
2.11.8
Subject: | test_leak.sql |
drop table if exists test_leak cascade;
create table test_leak
(
id serial NOT NULL,
numbers integer[],
string text NOT NULL,
CONSTRAINT test_leak_pkey PRIMARY KEY (id)
);
INSERT INTO test_leak (string,numbers) VALUES ('foo', '{}');
INSERT INTO test_leak (string) VALUES ('bar');
Subject: | leak.t |
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect('dbi:Pg:host=localhost;dbname=test;port=5432;',"postgres","postgres") or die($DBI::errstr);
my $count = 0;
my $sth = $dbh->prepare("SELECT * FROM test_leak WHERE string = ?");
while (1) {
{
$sth->execute('foo');
my $res = $sth->fetchall_arrayref({});
if ($res && @{$res}) {
$count += @{$res};
} else {
exit;
}
print "$count\n" if ($count % 1000 == 0);
}
}