Subject: | Slow but steady memory leak on last_insert_id calls |
Attached is a standalone program to demonstrate the problem. The
memory-info printout assumes a linux system (presence of /proc/<pid>/stat)
Cheers
Subject: | sqlite_leak.pl |
use strict;
use warnings;
use DBI;
my $db = 'memleak.db';
unlink $db;
my $dbi_dsn = "dbi:SQLite:$db";
my $dbh = init_db();
my $sth = $dbh->prepare_cached ('INSERT INTO test_leak DEFAULT VALUES');
my $count;
my $check_insert_id;
my $insert_id = 2**32; # pre-allocate variable (no idea if matters)
while (1) {
$count++;
$sth->execute;
$insert_id = $dbh->last_insert_id (undef, undef, 'test_leak', 'id')
if $check_insert_id;
$dbh->do ('DELETE FROM test_leak');
unless ($count % 5000) {
unless ($count % 30000) {
$check_insert_id = !$check_insert_id;
}
warn sprintf ("Cycles: %d\tFetching last_insert_id: %s\tProc size: %uK\n",
$count,
$check_insert_id ? 'Yes' : 'No',
(-f "/proc/$$/stat")
? do { local @ARGV="/proc/$$/stat"; (split (/\s/, <>))[22] / 1024 }
: -1
,
);
}
}
sub init_db {
unlink ($db);
my $dbh = DBI->connect ($dbi_dsn, undef, undef, { RaiseError => 1 });
$dbh->do ('PRAGMA SYNCHRONOUS=OFF');
$dbh->do ('DROP TABLE IF EXISTS test_leak');
$dbh->do (<<'EOS');
create table test_leak
(
id INTEGER PRIMARY KEY NOT NULL
)
EOS
return $dbh;
}