summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/gc.c b/gc.c
index 0c8069ea40..8c7db09f7b 100644
--- a/gc.c
+++ b/gc.c
@@ -1122,6 +1122,20 @@ rb_free_m_table(st_table *tbl)
}
static int
+free_method_cache_entry_i(ID key, method_cache_entry_t *entry, st_data_t data)
+{
+ free(entry);
+ return ST_CONTINUE;
+}
+
+void
+rb_free_mc_table(st_table *tbl)
+{
+ st_foreach(tbl, free_method_cache_entry_i, 0);
+ st_free_table(tbl);
+}
+
+static int
free_const_entry_i(ID key, rb_const_entry_t *ce, st_data_t data)
{
xfree(ce);
@@ -1226,7 +1240,6 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
break;
case T_MODULE:
case T_CLASS:
- rb_clear_cache_by_class((VALUE)obj);
if (RCLASS_M_TBL(obj)) {
rb_free_m_table(RCLASS_M_TBL(obj));
}
@@ -1239,7 +1252,23 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
if (RCLASS_IV_INDEX_TBL(obj)) {
st_free_table(RCLASS_IV_INDEX_TBL(obj));
}
- xfree(RANY(obj)->as.klass.ptr);
+ if (RCLASS_EXT(obj)->subclasses) {
+ if (BUILTIN_TYPE(obj) == T_MODULE) {
+ rb_class_detach_module_subclasses(obj);
+ } else {
+ rb_class_detach_subclasses(obj);
+ }
+ RCLASS_EXT(obj)->subclasses = NULL;
+ }
+ if (RCLASS_EXT(obj)->mc_tbl) {
+ rb_free_mc_table(RCLASS_EXT(obj)->mc_tbl);
+ RCLASS_EXT(obj)->mc_tbl = NULL;
+ }
+ rb_class_remove_from_module_subclasses(obj);
+ rb_class_remove_from_super_subclasses(obj);
+ if (RANY(obj)->as.klass.ptr)
+ xfree(RANY(obj)->as.klass.ptr);
+ RANY(obj)->as.klass.ptr = NULL;
break;
case T_STRING:
rb_str_free(obj);
@@ -1291,7 +1320,14 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
break;
case T_ICLASS:
/* iClass shares table with the module */
+ if (RCLASS_EXT(obj)->subclasses) {
+ rb_class_detach_subclasses(obj);
+ RCLASS_EXT(obj)->subclasses = NULL;
+ }
+ rb_class_remove_from_module_subclasses(obj);
+ rb_class_remove_from_super_subclasses(obj);
xfree(RANY(obj)->as.klass.ptr);
+ RANY(obj)->as.klass.ptr = NULL;
break;
case T_FLOAT: