How can I find a memory leak on Heroku?

青春壹個敷衍的年華 提交于 2019-12-03 01:53:05

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.

Install the New Relic add-on. It has a bunch of useful metrics that you can use to find out the source of the leak. I think its generally a better idea to try to see which part of the code takes the longest to execute and perhaps try to optimize that, rather than tweak the GC outright.

Some of the nice features New Relic includes is being able to pinpoint the source of the longest running SQL query, for example. I encourage you to give it a try.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!