# Memory leak in update from 2.1.2 to 2.2.2

**URL:** <https://www.ruby-forum.com/t/memory-leak-in-update-from-2-1-2-to-2-2-2/157498>\
**Category:** Rails\
**Created:** [January 12, 2009, 11:43am UTC](https://www.ruby-forum.com/t/memory-leak-in-update-from-2-1-2-to-2-2-2/157498 "2009-01-12T11:43:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wincent\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@Wincent\_C](https://www.ruby-forum.com/u/Wincent_C)\
**Post date:** [January 12, 2009, 11:43am UTC](https://www.ruby-forum.com/t/memory-leak-in-update-from-2-1-2-to-2-2-2/157498/1 "2009-01-12T11:43:48Z")

</div>

My last deployment was based on Rails 2.1.2 and would run for months  
without restarts and without leaking memory; memory would sit at  
around 35 to 40M per Mongrel instance.

On updating to 2.2.2 I’m seeing gradual memory bloat and every few  
days it hits its resource limit (130M per Mongrel) and monit does a  
restart.

I don’t think it’s a change in my own code that introduced the leak,  
seeing as I made only minimal changes necessary to fix breakage caused  
by updating Rails:

$ git diff 3f39f3a…5fc7345 --stat – app config lib  
app/controllers/application.rb | 26 ±----  
app/controllers/comments\_controller.rb | 4 ±  
app/helpers/application\_helper.rb | 10 +++  
app/helpers/articles\_helper.rb | 6 –  
app/models/user.rb | 4 ±  
app/views/articles/edit.html.haml | 2 ±  
app/views/articles/new.html.haml | 2 ±  
app/views/articles/show.html.haml | 2 ±  
app/views/comments/edit.html.haml | 2 ±  
app/views/issues/\_issues.html.haml | 2 ±  
app/views/search/\_article.html.haml | 2 ±  
app/views/search/\_issue.html.haml | 2 ±  
app/views/search/\_post.html.haml | 2 ±  
app/views/search/\_topic.html.haml | 2 ±  
config/boot.rb | 4 ±  
config/deploy.rb | 3 ±  
config/environment.rb | 14 ±–  
config/environments/development.rb | 2 -  
config/environments/production.rb | 2 -  
config/environments/test.rb | 8 ±-  
config/initializers/extensions.rb | 17 ++++  
config/locales/en.yml | 5 +  
lib/active\_record/acts/classifiable.rb | 2 ±  
lib/active\_record/acts/searchable.rb | 2 ±  
lib/sortable.rb | 2 ±  
lib/tasks/rspec.rake | 132 ++++++++++++++++++++++++  
++++++++  
26 files changed, 194 insertions(+), 67 deletions(-)

So I’m trying to hunt down the source of the leak, but it’s kind of  
intimidating because it’s almost certainly a change in “vendor”, which  
churned a whole lot from 2.1.2 to 2.2.2:

1313 files changed, 105152 insertions(+), 63806 deletions(-)

Wondering if anyone else has seen memory leaks creep in while moving  
from 2.1.2 to 2.2.2?

Cheers,  
Wincent

---

<div class="post-metadata">

**Author:** ![Wincent\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@Wincent\_C](https://www.ruby-forum.com/u/Wincent_C)\
**Post date:** [January 12, 2009, 11:56am UTC](https://www.ruby-forum.com/t/memory-leak-in-update-from-2-1-2-to-2-2-2/157498/2 "2009-01-12T11:56:11Z")

</div>

On 12 Jan 2009, at 10:42, Wincent C. wrote:

> My last deployment was based on Rails 2.1.2 and would run for months  
> without restarts and without leaking memory; memory would sit at  
> around 35 to 40M per Mongrel instance.
> 
> On updating to 2.2.2 I’m seeing gradual memory bloat and every few  
> days it hits its resource limit (130M per Mongrel) and monit does a  
> restart.

I know of two memory leaks in 2.2.2:

> <https://github.com/rails/rails/commit/9f69ff12d44c4d1e475fd6efede120ccedba3b3e>
>
> \[#1552 state:committed\]
> 
> Signed-off-by: Jeremy Kemper \<jeremy@bitsweat.net\>

> <https://github.com/rails/rails/commit/5ede4ce188d29aef94af78f27d89169ac4ee54cd>
>
> Signed-off-by: Joshua Peek \<josh@joshpeek.com\>

Fred

---

<div class="post-metadata">

**Author:** ![Wincent\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@Wincent\_C](https://www.ruby-forum.com/u/Wincent_C)\
**Post date:** [January 12, 2009, 12:19pm UTC](https://www.ruby-forum.com/t/memory-leak-in-update-from-2-1-2-to-2-2-2/157498/3 "2009-01-12T12:19:17Z")

</div>

On 12 ene, 11:55, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I know of two memory leaks in 2.2.2:
> 
> [http://github.com/rails/rails/commit/9f69ff12d44c4d1e475fd6efede120cc...http://github.com/rails/rails/commit/5ede4ce188d29aef94af78f27d89169a](http://github.com/rails/rails/commit/9f69ff12d44c4d1e475fd6efede120cc...http://github.com/rails/rails/commit/5ede4ce188d29aef94af78f27d89169a)…

Thanks a lot, Fred.

I’ll try applying both of those fixes before I go any further,  
although I suspect they aren’t the cause of the bloat I’m seeing (both  
of the pieces of code which got patched pre-date 2.1.2 and are  
relatively old, one from August 2008 and one from 2006, and I didn’t  
really see any memory bloat in 2.1.2).

Cheers,  
Wincent

---

<div class="post-metadata">

**Author:** ![Wincent\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@Wincent\_C](https://www.ruby-forum.com/u/Wincent_C)\
**Post date:** [January 21, 2009, 12:37pm UTC](https://www.ruby-forum.com/t/memory-leak-in-update-from-2-1-2-to-2-2-2/157498/4 "2009-01-21T12:37:24Z")

</div>

We had similar problem after upgrading from 2.1.0 to 2.2.2. Rails just  
kept accumulating memory. After we applied the buffered logger fix  
([Merge pull request #48654 from alpaca-tc/fix-typo-hash · rails/rails@be714e1 · GitHub](http://github.com/rails/rails/commit/)  
9f69ff12d44c4d1e475fd6efede120ccedba3b3e) we were back normal memory  
usage, no leaks.

---

<div class="post-metadata">

**Author:** ![Wincent\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@Wincent\_C](https://www.ruby-forum.com/u/Wincent_C)\
**Post date:** [January 21, 2009, 6:38pm UTC](https://www.ruby-forum.com/t/memory-leak-in-update-from-2-1-2-to-2-2-2/157498/5 "2009-01-21T18:38:47Z")

</div>

Ran into a similar problem as well. After a frustrating week basically  
unpacking all gems, and rebuilding our gem list fixed it (which is a  
terrible answer cause i can’t rightly say what caused the leak). Best  
i can tell there was some issue with different gems that caused a  
memory leak and removing and reinstalling them all seemed to resolve  
it. Note to self, always check gems into your project
