-
Notifications
You must be signed in to change notification settings - Fork 193
FIX: severe memory leak in WeakValueMap #336
Conversation
We used to leak some memory every time you cook a post see: rubyjs/therubyracer#336
entries were not being cleaned up correctly from the backing store
If I understand correctly, this is because while the referenced objects are being gc'd, the actual entries containing the week references are not? |
yes, exactly, blogged a bit about this as well. http://samsaffron.com/archive/2015/03/31/debugging-memory-leaks-in-ruby |
end | ||
|
||
def self.ensure_cleanup(values,key,ref) | ||
proc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what the reason to use proc {} ? Asking just for educational purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@novokshonovi regarding the reasoning for the class method and rather awkward definition of finalizers, you need to be ultra careful with closures: see http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/
👍 |
Released with v0.12.2 |
wow, awesome. time to kill my monkey patch :) On Tue, Apr 7, 2015 at 1:52 PM, Charles Lowell notifications@github.com
|
at_exit seems to leak memory. checked with below script (copied from SamSaffron's rubyjs/therubyracer#336) ``` require 'objspace' require 'memory_profiler' require 'fluent-logger' def rss `ps -eo pid,rss | grep #{Process.pid} | awk '{print $2}'`.to_i end MemoryProfiler::Helpers.full_gc puts "rss: #{rss} live objects #{GC.stat[:heap_live_slots]}" 20.times do 500.times { |i| Fluent::Logger::FluentLogger.new.post("tag", {"a"=>1}) } MemoryProfiler::Helpers.full_gc puts "rss: #{rss} live objects #{GC.stat[:heap_live_slots]}" end ``` before this patch ``` rss: 19528 live objects 38181 rss: 20836 live objects 46999 rss: 21108 live objects 54998 rss: 21948 live objects 62998 rss: 22992 live objects 70998 rss: 24192 live objects 78998 rss: 25248 live objects 86998 rss: 26324 live objects 94998 rss: 27432 live objects 102998 rss: 28556 live objects 110998 ... ... ``` after ``` rss: 19840 live objects 38181 rss: 20988 live objects 38998 rss: 21048 live objects 38997 rss: 21056 live objects 38997 rss: 21116 live objects 38997 rss: 21116 live objects 38997 rss: 21116 live objects 38997 rss: 21116 live objects 38997 rss: 21116 live objects 38997 rss: 21116 live objects 38997 rss: 21116 live objects 38997 rss: 21116 live objects 38997 ... ... ```
This adds a regression for: #336
entries were not being cleaned up correctly from the backing store. Impact is huge:
Before
After
Recommend a new stable release with this asap. Deploying a monkey patch to Discourse