shameless plug: I've made malloc hooking preload library for hunting such bugs, that automatizes most of the described work - https://github.com/samsk/log-malloc2
How I spent two weeks hunting a memory leak in Ruby (2015)
21–30 of 71 posts
Re: How I spent two weeks hunting a memory leak in Ruby (2015)
#22Does PHP have similar issues? I think it shouldn't.
However, you can still create memory leaks just like you could in Ruby - dynamic allocation in a c extension that isn't freed up (like in this story), or creating objects that can't be garbage collected (like a slowing expanding array in a global variable).
Re: How I spent two weeks hunting a memory leak in Ruby (2015)
#23Does PHP have similar issues? I think it shouldn't.
But no, a PHP extension in C can have a memory leak like any other C code. It's not at all uncommon actually, since there are fewer consequences; CGI mode PHP cleans up after every request, FastCGI mode PHP by default restarts workers after a number of requests because of the class of effects (unwanted state) that includes memory leaks.
Re: How I spent two weeks hunting a memory leak in Ruby (2015)
#24Re: How I spent two weeks hunting a memory leak in Ruby (2015)
#25I get that it means you have to "run a server", and insert arguments for expensive cloud providers vs DIY servers here but I don't think it's any less crazy than being forced to chase a GC white whale for two weeks on a tiny memory leak to avoid a huge rate hike on your hosting bill.
On an aside, I've only had one problematic memory leak with ruby ever (the infamously leaky RMagick), I threw this in every time I used the lib and it solved it for me:
GC.start(full_mark: true, immediate_sweep: true)
Bit of a performance hit, but not enough to cause a problem for my use case.Re: How I spent two weeks hunting a memory leak in Ruby (2015)
#26About the patch at https://github.com/vmg/redcarpet/pull/516/files , couldn't the update simply have been the following? - return Data_Wrap_Struct(klass, rb_redcarpet_rbase_mark, NULL, rndr); + return Data_Wrap_Struct(klass, rb_redcarpet_rbase_mark, xfree, rndr);
C is not really my area of expertise, but doesn't xfree have alternatives? like free, freeif, etc? I'd much rather have to change that later in one place than several (if there end up being more calls to xfree in the code) if at some point the implementation needs to change again.
[1] http://clalance.blogspot.com/2011/01/writing-ruby-extensions... [2] http://inferior-products.com/docs/userdocs/ruby19/html/d8/d1...
Re: How I spent two weeks hunting a memory leak in Ruby (2015)
#27Earlier quoted context omitted.
C is not really my area of expertise, but doesn't xfree have alternatives? like free, freeif, etc? I'd much rather have to change that later in one place than several (if there end up being more calls to xfree in the code) if at some point the implementation needs to change again.
So a from a quick googling it looks like xfree()[1] is a ruby specific thing, and should be used internally for everything allocated by ruby. It also looks like it's got the same signature as the function created for this so that should work there too. [2] [1] http://clalance.blogspot.com/2011/01/writing-ruby-extensions... [2] http://inferior-products.com/docs/userdocs/ruby19/html/d8/d1...
Re: How I spent two weeks hunting a memory leak in Ruby (2015)
#28Interesting post, but I did want to chime in quickly and say that it's pretty absurd to only have 1GB for a web application in 2016, even for a small one. This is why I've been dismissive of using Heroku for my projects, even though I run a lean stack. They have higher RAM options, but they are incredibly expensive. For the cost of a 14GB Heroku Dyno, I can buy a dedicated server off ebay with 32GB ECC every single m…
While I don't for a minute doubt what you say, as an old guy, the absurdity of 1GB being insufficient for serving up web pages hits me pretty hard.
Re: How I spent two weeks hunting a memory leak in Ruby (2015)
#29Earlier quoted context omitted.
So a from a quick googling it looks like xfree()[1] is a ruby specific thing, and should be used internally for everything allocated by ruby. It also looks like it's got the same signature as the function created for this so that should work there too. [2] [1] http://clalance.blogspot.com/2011/01/writing-ruby-extensions... [2] http://inferior-products.com/docs/userdocs/ruby19/html/d8/d1...
...Are you sure? I was pretty sure that it gets it from the same place as xmalloc...wouldn't that be in libc?
Re: How I spent two weeks hunting a memory leak in Ruby (2015)
#30Earlier quoted context omitted.
...Are you sure? I was pretty sure that it gets it from the same place as xmalloc...wouldn't that be in libc?
There is no xmalloc in the libc.
Publib then? I'm finding this when I search: http://man.cx/xfree(3) http://man.cx/publib(3)
Also, are you sure? I see xmalloc in glibc all over the internet...