From dae0de44617cf9e4584f8aa8cd34db4cd928a0c8 Mon Sep 17 00:00:00 2001 From: Rory OConnell <19547+RoryO@users.noreply.github.com> Date: Sat, 29 Aug 2020 17:19:49 -0700 Subject: Add call to malloc_trim on a full GC --- src/gc.c | 6 ++++++ tasks/toolchains/gcc.rake | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/gc.c b/src/gc.c index 393f7f62c..302d5cd68 100644 --- a/src/gc.c +++ b/src/gc.c @@ -6,6 +6,9 @@ #include #include +#ifdef HAS_MALLOC_TRIM +#include +#endif #include #include #include @@ -1319,6 +1322,9 @@ mrb_full_gc(mrb_state *mrb) gc->full = FALSE; } +#ifdef HAS_MALLOC_TRIM + malloc_trim(0); +#endif GC_TIME_STOP_AND_REPORT; } diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake index 810f23b7a..3d55e6171 100644 --- a/tasks/toolchains/gcc.rake +++ b/tasks/toolchains/gcc.rake @@ -31,6 +31,8 @@ MRuby::Toolchain.new(:gcc) do |conf, params| end [[conf.cc, 'c'], [conf.cxx, 'c++']].each do |cc, lang| + cc.defines += %w(HAS_MALLOC_TRIM) if cc.has_function? 'malloc_trim', with_header: 'malloc.h' + cc.instance_variable_set :@header_search_language, lang def cc.header_search_paths if @header_search_command != command -- cgit v1.2.3