From 3aab1f8467010bcb81081b55eef191452102ffa6 Mon Sep 17 00:00:00 2001 From: normal Date: Wed, 1 Oct 2014 20:36:28 +0000 Subject: io.c (fptr_finalize): free memory before GC sweep This releases memory on explict calls to rb_io_close, reducing pressure on the GC. Final massif snapshot shows reduced heap usage after RubyGems load (valgrind --tool=massif ./ruby -e exit) before: mem_heap_B=4821992 mem_heap_extra_B=1302952 after: mem_heap_B=4791056 mem_heap_extra_B=1192440 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ io.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2f3cb86779..99b7b0bfef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Oct 2 05:32:17 2014 Eric Wong + + * io.c (fptr_finalize): free memory before GC sweep + [ruby-core:65269] [Feature #10295] + Thu Oct 2 05:27:24 2014 Eric Wong * marshal.c (w_class): check dump_arg->compat_tbl before lookup diff --git a/io.c b/io.c index 876ae675a4..f4b41dd21a 100644 --- a/io.c +++ b/io.c @@ -4251,6 +4251,9 @@ maygvl_fclose(FILE *file, int keepgvl) return (int)(intptr_t)rb_thread_call_without_gvl(nogvl_fclose, file, RUBY_UBF_IO, 0); } +static void free_io_buffer(rb_io_buffer_t *buf); +static void clear_codeconv(rb_io_t *fptr); + static void fptr_finalize(rb_io_t *fptr, int noraise) { @@ -4312,6 +4315,9 @@ fptr_finalize(rb_io_t *fptr, int noraise) rb_exc_raise(err); } } + free_io_buffer(&fptr->rbuf); + free_io_buffer(&fptr->wbuf); + clear_codeconv(fptr); } static void -- cgit v1.2.3