-->

Rails 3.1, memory leak for missing local partial v

2019-02-26 02:50发布

问题:

If I render a partial like so:

= render :partial => "event_news_item", :object => event, :variable => true

And then reference variable in the partial a memory leak is triggered. It seems rails goes into a recursion. I have to then quickly restart my server before memory usage spirals out of control.

Anyone knows why the memory leak is triggered here? Can anyone confirm this on their machine?

If I do

= render :partial => "event_news_item", :object => event

An error is raised correctly when trying to reference variable in the partial.

(The correct way of doing this by the way is

= render :partial => "event_news_item", :object => event, :locals => { :variable => true })

回答1:

I have seen a really bad memory leak in similar environment. I've tracked it to the innocently looking association fetch (comment.author, to be precise), then tried to debug it for some time, and finally gave up and ran on 1.9.3-rc1.

Surprisingly, that fixed this particular memory leak, and, moreover, reduced the unicorns' startup size by 15M (from 85M to 70M; i386).