问题描述
如果我这样渲染局部图像:
If I render a partial like so:
=渲染:partial =>"event_news_item",:object => event,:variable => true
= render :partial => "event_news_item", :object => event, :variable => true
然后在触发内存泄漏的部分中引用变量.似乎rails进入了递归过程.然后,我必须迅速重新启动我的服务器,然后内存使用率才会失控.
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.
有人知道为什么在这里触发内存泄漏吗?谁能在自己的计算机上确认这一点?
如果我这样做
=渲染:partial =>"event_news_item",:object =>事件
= 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
=渲染:partial =>"event_news_item",:object => event,:locals => {:variable => true})
= render :partial => "event_news_item", :object => event, :locals => { :variable => true })
推荐答案
在相似的环境中,我看到了非常糟糕的内存泄漏.我已经将其跟踪到看起来很天真的关联获取(准确地说是comment.author
),然后尝试对其进行调试了一段时间,最后放弃并运行了1.9.3-rc1.
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.
令人惊讶的是,这修复了此特定的内存泄漏,而且将独角兽的启动大小减少了15M(从85M减少到70M; i386).
Surprisingly, that fixed this particular memory leak, and, moreover, reduced the unicorns' startup size by 15M (from 85M to 70M; i386).
这篇关于Rails 3.1,缺少局部局部变量的内存泄漏(Ruby 1.9.2-p290)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!