Ruby <2.7now uses WeakMap too, which prevents memory leaks.
Ruby <2.7 does not allow non-finalizable objects to be WeakMap
keys: https://bugs.ruby-lang.org/issues/16035
We work around this by using a secondary map for Ruby <2.7 which
maps the non-finalizable integer to a distinct object.
For now we accept that the entries in the secondary map wil never
be collected. If this becomes a problem we can perform a GC pass
every so often that looks at the contents of the object cache to
decide what can be deleted from the secondary map.
diff --git a/ruby/ext/google/protobuf_c/defs.c b/ruby/ext/google/protobuf_c/defs.c
index 10ded86..1d912c1 100644
--- a/ruby/ext/google/protobuf_c/defs.c
+++ b/ruby/ext/google/protobuf_c/defs.c
@@ -295,7 +295,7 @@
self->def_to_descriptor = rb_hash_new();
self->symtab = upb_symtab_new();
- ObjectCache_Add(self->symtab, ret, _upb_symtab_arena(self->symtab));
+ ObjectCache_Add(self->symtab, ret);
return ret;
}