# Find\_each leaks (a lot)?

**URL:** <https://www.ruby-forum.com/t/find-each-leaks-a-lot/182710>\
**Category:** Rails\
**Created:** [February 1, 2010, 7:54pm UTC](https://www.ruby-forum.com/t/find-each-leaks-a-lot/182710 "2010-02-01T19:54:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PierreW](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@PierreW](https://www.ruby-forum.com/u/PierreW)\
**Post date:** [February 1, 2010, 7:54pm UTC](https://www.ruby-forum.com/t/find-each-leaks-a-lot/182710/1 "2010-02-01T19:54:35Z")

</div>

Hi guys,

I need to load a big amount of records from a table (around 20000). So  
I am using find\_each. In the RDoc it says:  
“When processing large numbers of records, it‘s often a good idea to  
do so in batches to prevent memory ballooning.”

I am not sure I get it though, indeed:

1- If I do:

Foo.find\_each(:batch\_size =\> 1000) do |lfoo|  
end

RAM use go from 33MB before to 92MB after.

2- Now if I do:

temp = Foo.find(:all, :limit =\> 1000)

RAM use go from 33MB before to 35MB after.

How come does find\_each use so much memory? I must be missing  
something obvious?

I am on Rails 2.3.2.

Thanks a lot,  
Pierre
