From: "Berger, Daniel" Date: 2004-01-14T05:37:11+09:00 Subject: Slow memory leak with 1.8.1, rb_yield Hi all, I've only tested this so far on Windows XP with VC++ 7. I noticed that there's a slow memory leak in rb_yield (I think) in 1.8.1. Here's the sample code: // foo.c #include "ruby.h" #include static VALUE foo_test(VALUE class){ rb_yield(rb_str_new2("hello")); return Qnil; } void Init_foo(){ VALUE cFoo = rb_define_class("Foo",rb_cObject); rb_define_singleton_method(cFoo,"test",foo_test,0); } // end foo.c # extconf.rb require "mkmf" create_makefile("foo") # end extconf.rb # Sample test script - watch "Mem Usage" in Task Manager while running $:.unshift Dir.pwd require "foo" n = 1 while true Foo.test{ |x| p x puts } puts "Iteration #{n}" n += 1 sleep 0.5 end # end test script This leaks at about 4k per 20 iterations (204b per iteration). It does go away if I add an explicit rb_gc() after the rb_yield(). I guess my question is, why do I have to manually garbage collect after an rb_yield()? Should this be standard operating procedure? Regards, Dan