S
Sebastian probst Eide
Hi
I am currently learning to use Ruby-DBI and have a really simple script
(pasted below). The problem I am having is that the program seems to be
leaking memory! When monitoring it in the activity monitor (MacOSX) I
can see that the process uses 100kb more memory every second! Why does
this happen? I am planning to write a little daemon that is going to run
non-stop on a server and can't have it leak memory. Is it dbi that is
leaking or is there something in my code?
If I let it run for 24 hours the process would take 8,6gb of memory
instead of the 3mb it started out with, and my server isn't up for that!
Hope you have any suggestions.
I also tried a patch to the ruby-mysql api which was supposed to handle
some memory leak, but it didn't improve my test scenario...
(http://railsexpress.de/blog/articles/2006/10/05/make-ruby-mysql-create-less-garbage)
#!/usr/bin/ruby -w
require "dbi"
while true
begin
# connect to the MySQL server
dbh = DBI.connect("DBI:Mysql:test:localhost", "root", "")
# get server version string and display it
row = dbh.select_one("SELECT VERSION()")
puts "Server version: " + row[0]
rescue DBI:atabaseError => e
puts "An error occurred"
puts "Error code: #{e.err}"
puts "Error message: #{e.errstr}"
ensure
# disconnect from server
dbh.disconnect if dbh
end
end
I am currently learning to use Ruby-DBI and have a really simple script
(pasted below). The problem I am having is that the program seems to be
leaking memory! When monitoring it in the activity monitor (MacOSX) I
can see that the process uses 100kb more memory every second! Why does
this happen? I am planning to write a little daemon that is going to run
non-stop on a server and can't have it leak memory. Is it dbi that is
leaking or is there something in my code?
If I let it run for 24 hours the process would take 8,6gb of memory
instead of the 3mb it started out with, and my server isn't up for that!
Hope you have any suggestions.
I also tried a patch to the ruby-mysql api which was supposed to handle
some memory leak, but it didn't improve my test scenario...
(http://railsexpress.de/blog/articles/2006/10/05/make-ruby-mysql-create-less-garbage)
#!/usr/bin/ruby -w
require "dbi"
while true
begin
# connect to the MySQL server
dbh = DBI.connect("DBI:Mysql:test:localhost", "root", "")
# get server version string and display it
row = dbh.select_one("SELECT VERSION()")
puts "Server version: " + row[0]
rescue DBI:atabaseError => e
puts "An error occurred"
puts "Error code: #{e.err}"
puts "Error message: #{e.errstr}"
ensure
# disconnect from server
dbh.disconnect if dbh
end
end