Actions
Bug #13498
closedWeakref, Weakmap and define_finalizer don't work on frozen objects
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] (but seen the same issue with 2.3 and 2.1)
Description
I'm just creating a single ticket for these issues, I guess they're actually all the same (I've seen weakref uses weakmap, not sure about define_finalizer).
require 'weakref'
map = ObjectSpace::WeakMap.new
o = Object.new
o.freeze
begin
WeakRef.new(o)
rescue => e
STDERR.puts e
end
begin
map[o] = 'foo'
rescue => e
STDERR.puts e
end
begin
map['bar'] = o
rescue => e
STDERR.puts e
end
begin
ObjectSpace.define_finalizer(o, ->(id) { p id })
rescue => e
STDERR.puts e
end
Every statement here raises the runtime error "can't modify frozen Object". The documentation doesn't mention that frozen objects are not allowed, the closest reference we get is a short paragraph in WeakRef: "With this you will have to limit your self to String keys, otherwise you will get an ArgumentError because WeakRef cannot create a finalizer for a Symbol. Symbols are immutable and cannot be garbage collected"
Actions
Like0
Like0Like0Like0