I am using Class::DBI to describe various tables and add new data records to them. As I add 1000's of new records using ->create() the Perl program memory size grows proportionally to record count and average data size per record. Memory is not released until end of program.
I'd thought that with the default Class::DBI setting of AutoCommit=>1 I'd not need to worry about 'details' like records accumulating until I did an explicit commit. I'm afraid something more subtle is wrong (with my understanding of course). Example program is as follows:
Sanity check output is:use strict; use warnings; package MyTest1; use base 'Class::DBI'; __PACKAGE__->set_db('Main', 'dbi:mysql:test', undef, undef, { RaiseErr +or => 1 } ); __PACKAGE__->table('test1'); __PACKAGE__->columns( All => qw( id logtext ) ); package main; printf " db_Main is '%s'\n", MyTest1->db_Main; printf " AutoCommit is '%s'\n", MyTest1->db_Main->{AutoCommit}; printf " RaiseError is '%s'\n", MyTest1->db_Main->{RaiseError}; MyTest1->db_Main->do( 'DROP TABLE IF EXISTS test1' ); MyTest1->db_Main->do( <<EOSQL ); CREATE TABLE IF NOT EXISTS test1 ( id INTEGER NOT NULL, logtext VARCHAR(255) NOT NULL, PRIMARY KEY (id) ) EOSQL my $newentry; for( my $i=0 ; $i<10000 ; ++$i ) { $newentry = MyTest1->create( { id=>$i, logtext=>'faked' } ); unless( $newentry ) { printf "*Error: Unable to create new entry object\n"; last; } } my( $count ) = MyTest1->db_Main->selectrow_array( 'SELECT count(*) FROM test1' ); printf " Record count '%d'\n", $count; printf " db_Main is '%s'\n", MyTest1->db_Main; printf " AutoCommit is '%s'\n", MyTest1->db_Main->{AutoCommit};
db_Main is 'Ima::DBI::db=HASH(0x2343a38)' AutoCommit is '1' RaiseError is '1' Record count '10000' db_Main is 'Ima::DBI::db=HASH(0x2343a38)' AutoCommit is '1'
Environment is WinXP, ActiveState 5.6.1 build 635, Class::DBI 0.94, DBD::mysql 2.9002, MySQL 3.23.52
In reply to Class::DBI and create: program memory just grows and grows by shenme
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |