Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
FIX: severe memory leak in WeakValueMap
Browse files Browse the repository at this point in the history
entries were not being cleaned up correctly from the backing store
  • Loading branch information
SamSaffron committed Apr 1, 2015
1 parent 8dae8f7 commit 3b4b2af
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/v8/weak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ def [](key)
end

def []=(key, value)
@values[key] = V8::Weak::Ref.new(value)
ref = V8::Weak::Ref.new(value)
ObjectSpace.define_finalizer(value, self.class.ensure_cleanup(@values, key, ref))

@values[key] = ref
end

private

def self.ensure_cleanup(values,key,ref)
proc {
values.delete(key) if values[key] == ref
}
end
end
end
Expand Down

0 comments on commit 3b4b2af

Please sign in to comment.