# Mysql-ruby gem using significantly more memory that mysql.rb?

**URL:** <https://www.ruby-forum.com/t/mysql-ruby-gem-using-significantly-more-memory-that-mysql-rb/119581>\
**Category:** Rails\
**Created:** [November 8, 2007, 5:35am UTC](https://www.ruby-forum.com/t/mysql-ruby-gem-using-significantly-more-memory-that-mysql-rb/119581 "2007-11-08T05:35:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sillydude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@sillydude](https://www.ruby-forum.com/u/sillydude)\
**Post date:** [November 8, 2007, 5:35am UTC](https://www.ruby-forum.com/t/mysql-ruby-gem-using-significantly-more-memory-that-mysql-rb/119581/1 "2007-11-08T05:35:45Z")

</div>

I have found that, using the mysql-ruby gem leads to 40 MB more memory  
consumption in my tests than plain mysql.rb.

Is anyone aware of this?

My test loads a nasty grid of values using many include statements  
which result in about 5000 rows being returned (the actual number of  
rows is much less but the joins increase the number).

When using ruby-mysql:  
The memory usage jumps from ~75megs to 161megs after executing  
result.all\_hashes and does not go back down.

When using mysql.rb:  
The memory usage jumps from ~75megs to 121megs after executing  
result.all\_hashes and does not go back down.

I have two major concerns…

1.) why doesn’t the process eventually release the memory that is used  
up? I am destroying all references to the grid and calling GC.start to  
be sure  
2.) why does ruby-mysql use significantly more memory than mysql.rb?

I appreciate any help and will continue investigating on my own in the  
mean time.

(I already posted this in the core list, but realized that since I  
don’t have a fix yet and since mysql-ruby is outside of rails it would  
probably be more appropriate here.)

Thanks,  
Kris

---

<div class="post-metadata">

**Author:** ![sillydude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@sillydude](https://www.ruby-forum.com/u/sillydude)\
**Post date:** [November 8, 2007, 2:44pm UTC](https://www.ruby-forum.com/t/mysql-ruby-gem-using-significantly-more-memory-that-mysql-rb/119581/2 "2007-11-08T14:44:52Z")

</div>

Hi Kris,

> I have found that, using the mysql-ruby gem leads to 40 MB more memory  
> consumption in my tests than plain mysql.rb.
> 
> Is anyone aware of this?

Yeah, MySQL/Ruby is known to create an overly amount of garbage. Stefan  
Kaes has a patch for it [1] and I provide a compiled set of MySQL/Ruby  
adapters for Windows that have got this patch [2].

[1]  
[https://railsexpress.de/blog/articles/2006/10/05/make-ruby-mysql-create-less-garbage](https://railsexpress.de/blog/articles/2006/10/05/make-ruby-mysql-create-less-garbage)  
[2] [http://www.vandomburg.net](http://www.vandomburg.net) (currently migrating to another host;  
adapters will be back up soon)

–  
Roderick van Domburg  
[http://www.nedforce.com](http://www.nedforce.com)

---

<div class="post-metadata">

**Author:** ![sillydude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90ced4/32.png) [@sillydude](https://www.ruby-forum.com/u/sillydude)\
**Post date:** [November 8, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/mysql-ruby-gem-using-significantly-more-memory-that-mysql-rb/119581/3 "2007-11-08T15:15:10Z")

</div>

On Nov 7, 2007 11:35 PM, SillyDude [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 1.) why doesn’t the process eventually release the memory that is used  
> up? I am destroying all references to the grid and calling GC.start to  
> be sure

GC returns the memory to the internal free pool, but the memory is  
never returned to the operating system. This isn’t a Ruby-specific  
thing; most programs work the same way. The only way to accomplish  
that is to have the program re-exec itself.
