How can I find a memory leak on Heroku?

前端 未结 2 1190
别那么骄傲
别那么骄傲 2021-02-05 11:18

I have a Rails 3.2.8 app running on Heroku Cedar with Ruby 1.9.3. The app runs fine when it launches but after a day or so of continuous use, I start to see R14 errors on my log

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-05 11:52

    The GC should do the clean up, and probably does.

    You can force the GC with GC.start; if many objects were not collected this will, but I suspect that is not the issue.

    Is it possible you somehow create a bunch of objects and never release them, by keeping cached copies or something?

    I'm unfamiliar with the existing tools to check this, but you may want to check which objects exist using ObjectSpace. For example:

    ObjectSpace.each_object.with_object(Hash.new(0)){|obj, h| h[obj.class] +=1 }
    # => a Hash with the number of objects by class
    

    If you get an unexpected number for one of your classes, for instance, you would have a better idea of where to look for.

提交回复
热议问题