Register mark objects so Protobuf is compaction friendly This commit removes an unused reference and registers globals with the GC so that they will never die. Ruby is getting a compacting GC, and it means that these references can move. Registering them with `rb_gc_register_mark_object` will ensure the constants don't move and will not be collected.
diff --git a/ruby/ext/google/protobuf_c/protobuf.c b/ruby/ext/google/protobuf_c/protobuf.c index c27f30a..c9eecee 100644 --- a/ruby/ext/google/protobuf_c/protobuf.c +++ b/ruby/ext/google/protobuf_c/protobuf.c
@@ -37,7 +37,7 @@ #include "message.h" #include "repeated_field.h" -VALUE cError; +VALUE cParseError; VALUE cTypeError; const upb_fielddef* map_field_key(const upb_fielddef* field) { @@ -368,8 +368,10 @@ Map_register(protobuf); Message_register(protobuf); - cError = rb_const_get(protobuf, rb_intern("Error")); + cParseError = rb_const_get(protobuf, rb_intern("ParseError")); + rb_gc_register_mark_object(cParseError); cTypeError = rb_const_get(protobuf, rb_intern("TypeError")); + rb_gc_register_mark_object(cTypeError); rb_define_singleton_method(protobuf, "discard_unknown", Google_Protobuf_discard_unknown, 1);