mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
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>
This commit is contained in:
parent
b361a800c2
commit
6816e8efcf
27 changed files with 285 additions and 6 deletions
27
variable.c
27
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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue