aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
authorAdam Hess <adamhess1991@gmail.com>2023-10-12 11:15:53 -0700
committerPeter Zhu <peter@peterzhu.ca>2023-12-07 15:52:35 -0500
commit6816e8efcff3be75f8020cd1b0ea57d3cd664bbc (patch)
tree8f8484b955ba25e9df6a2038db0f156e7cbf71e4 /variable.c
parentb361a800c22e0248bf126d77e96a7bd4f9c34d1b (diff)
downloadruby-6816e8efcff3be75f8020cd1b0ea57d3cd664bbc.tar.gz
Free everything at shutdown
when the RUBY_FREE_ON_SHUTDOWN environment variable is set, manually free memory at shutdown. Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Co-authored-by: Peter Zhu <peter@peterzhu.ca>
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/variable.c b/variable.c
index 4c2bc5c97e..de3a3561f8 100644
--- a/variable.c
+++ b/variable.c
@@ -438,6 +438,33 @@ struct rb_global_entry {
bool ractor_local;
};
+static enum rb_id_table_iterator_result
+free_global_entry_i(ID key, VALUE val, void *arg)
+{
+ struct rb_global_entry *entry = (struct rb_global_entry *)val;
+ if (entry->var->counter == 1) {
+ ruby_xfree(entry->var);
+ }
+ else {
+ entry->var->counter--;
+ }
+ ruby_xfree(entry);
+ return ID_TABLE_DELETE;
+}
+
+void
+rb_free_rb_global_tbl(void)
+{
+ rb_id_table_foreach(rb_global_tbl, free_global_entry_i, 0);
+ rb_id_table_free(rb_global_tbl);
+}
+
+void
+rb_free_generic_iv_tbl_(void)
+{
+ st_free_table(generic_iv_tbl_);
+}
+
static struct rb_global_entry*
rb_find_global_entry(ID id)
{