Reputation: 1007
So I've got this rails app with a horrible memory leak problem. I'm running it on Heroku, and for the last couple days while I've been trying to figure out what on earth is causing it, I've had to continually restart the app every 5 hours or so or the memory exceeds 512 and my app crashes.
I'm using Oink, and I'm not seeing anything fishy with my instantiated classes. The only thing is that with each page load, the memory used creeps up. It doesn't even matter which page I load, it's seemingly random.
New Relic hasn't been much help either, since it doesn't have to do with any one particular controller action.
The only thing I've been able to find was using ObjectSpace, which revealed an ENORMOUS number of string objects in memory, and the number just grows and grows. I used a little tool to log the value of the strings and they're all blank. Not nil... but whitespace. My production app regularly has over 200,000 string objects in use.
Does anyone have any idea what these could possibly be coming from? This is really stressing me out having to be at my computer every five hours to keep my site alive.
Thanks!
Upvotes: 5
Views: 1340
Reputation: 1007
Okay, this is absolutely ridiculous, but after two weeks of anxiety and struggle, I found the solution to this leak. It literally all came down to this one line:
ActionMailer::Base.delivery_method = :smtp
in my application.rb config file.
It should have been:
config.action_mailer.delivery_method = :smtp
I have no idea how I got it wrong, but boy did it wreak havoc on my app.
Does anyone know why this would cause such a problem? I was losing about a megabyte of memory on every single query. Crazy.
Upvotes: 9