I am using dbd-mysql (0.4.2) and dbi 0.4.1 on Window XP/Vista/2003. I found memory leak. My Ruby version is 1.8.6. For
my test code which is listed below, it can leak more than 3M a day. Here is the test code:
require 'rubygems'
require 'dbi'
host = 'localhost'
db = 'leaktest'
port = 3306
user = 'leaktest'
pw = 'kael4'
connection = DBI.connect("DBI:Mysql:#{host};database=#{db};port=#{port}", "#{user}",
"#{pw}")
i = 1
name = 'test'
while true do
value = name + i.to_s
sql = "insert into test (name) values ('#{value}');"
#sth = connection.execute(sql)
rows = connection.do(sql)
sleep 0.5
#sth.finish
i += 1
end
here are the statement to setup database and table:
mysql> create database leaktest;
mysql> use leaktest;
mysql> create table test ( ID int(11) NOT NULL auto_increment, name varchar(20) not null, CONSTRAINT PK_test_id PRIMARY
KEY (ID) );
mysql> grant select,update,insert,delete,execute,create,drop,alter on leaktest.* to leaktest@localhost identified
by 'kael4';
The leak occurs by using either 'do' or 'execute' (need finish sth) methods. let it run more than one day. you will
see the leak. If the table is more complex, it is easier to reproduce. For above test, if it sleeps more time, it leaks
less. but my application code need insert record quite often.
Qi
ps. this code does not leak (or much less) in SQL server database (dbd-odbc) |