# Mysql gem memory leak

**URL:** <https://www.ruby-forum.com/t/mysql-gem-memory-leak/170568>\
**Category:** Ruby\
**Created:** [June 19, 2009, 5:00am UTC](https://www.ruby-forum.com/t/mysql-gem-memory-leak/170568 "2009-06-19T05:00:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [June 19, 2009, 5:00am UTC](https://www.ruby-forum.com/t/mysql-gem-memory-leak/170568/1 "2009-06-19T05:00:13Z")

</div>

I have a tiny script that just opens a database connection and then  
repeats:  
1) do a query and free the response, and  
2) sleep for a few seconds.

Note that this is not using ActiveRecord or any other Rails bits, but  
just the straight ruby-mysql bindings. Also note that in this particular  
test, the response is always empty; there are no records that match the  
query.

The application memory increases over time, so that within a few hours,  
it’s consuming hundreds of Mb. Anyone else seen this? Is it a version  
problem?

Thanks,

Aaron

Versions:

ruby 1.8.7 (2009-04-08 patchlevel 160) [x86\_64-linux]

\*\*\* LOCAL GEMS \*\*\*  
mysql (2.7)

Linux version 2.6.24-23-xen (buildd@crested) (gcc version 4.2.3 (Ubuntu  
4.2.3-2ubuntu7)) #1 SMP Mon Jan 26 03:09:12 UTC 2009

mysql Server version 5.0.51a-3ubuntu5.4

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [June 19, 2009, 8:09pm UTC](https://www.ruby-forum.com/t/mysql-gem-memory-leak/170568/2 "2009-06-19T20:09:31Z")

</div>

> Versions:
> 
> ruby 1.8.7 (2009-04-08 patchlevel 160) [x86\_64-linux]
> 
> \*\*\* LOCAL GEMS \*\*\*  
> mysql (2.7)
> 
> Linux version 2.6.24-23-xen (buildd@crested) (gcc version 4.2.3 (Ubuntu  
> 4.2.3-2ubuntu7)) #1 SMP Mon Jan 26 03:09:12 UTC 2009

I haven’t seen that particular problem before. You could try a newer  
version of the gem [2.8.1] or mysqlplus, or the MBARI patches of Ruby,  
or try running it with valgrind [you may have found a real leak].  
Cheers!  
-=r
