# Very strange - major leak, crashed mongrel

**URL:** <https://www.ruby-forum.com/t/very-strange-major-leak-crashed-mongrel/117562>\
**Category:** Rails\
**Created:** [October 18, 2007, 3:11am UTC](https://www.ruby-forum.com/t/very-strange-major-leak-crashed-mongrel/117562 "2007-10-18T03:11:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcbey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@marcbey](https://www.ruby-forum.com/u/marcbey)\
**Post date:** [October 18, 2007, 3:11am UTC](https://www.ruby-forum.com/t/very-strange-major-leak-crashed-mongrel/117562/1 "2007-10-18T03:11:07Z")

</div>

I made what I think is a small change yet the change in my app was  
disastrous - cpu spun, memory went out of control, and mongrel crashed  
within seconds.

I have a controller which takes a param for submission\_id . Submissions  
have 1 or more reviews, and reviews each have one image. There may be  
more  
than one image per submission.

The view (and partial) code does some very intense things, like @  
submission.reviews.each | review |  
review.image.imageprofile.releases.empty?  
, etc. No doubt causes huge joins and queries down the stack.

I built a query for a subset of the reviews belonging to @submission:  
@current\_reviews = Review.find(:all, :conditions =\> cond)

The query takes 20 milliseconds. [cond is along the lines of finding  
max(id) where submission\_id=@submission.id group by image\_id ]

Then when I try to loop thru these in view, replacing @  
submission.reviews.each with @current\_reviews.each , it leaks like  
crazy!  
Same code works just fine w/ @submission.reviews.each…

The partial that it’s rendering in that loop is huge - 150 lines of  
code,  
with all kinds of join-inducing references. Why would this behavior be  
any  
different for a SUBSET ?

Thanks in advance for any insights, things to try, places to look, etc.

Cheers,

Marc
