From: Noah Easterly Date: 2007-04-09T09:40:07+09:00 Subject: Re: rb_yield(), break, and C extensions On Apr 7, 3:39 pm, "Kent Sibilev" wrote: > OK, maybe this code will clean things up: > [...] Now I understand. So, the rb_ensure() only makes sure that it's third argument is called, not that anything after that in the function containing rb_ensure() is run. That's what I thought it was doing - which was leading me astray. So the original definition of func (which allocated memory, used the callback, freed memory, and didn't use ruby.h) won't work, I need to divide that into 3 parts (one to alloc, one that uses the callback, and one to free), and do something like: static VALUE my_meth(VALUE self) { MyType * my_type = AllocMyType(); rb_ensure(DoStuff, my_type, FreeMyType, my_type); return Qnil; } Thanks for bearing with me and explaining.