Mauricio Fernández
9/3/2003 9:52:00 PM
On Thu, Sep 04, 2003 at 03:43:21AM +0900, Sean O'Dell wrote:
> I thought I had read everything I needed about the Ruby GC, but
> something just popped up that took me by surprise.
>
> I am allocating a structure using malloc in QuiXML (in C), then wrapping
> it in Data_Wrap_Struct, providing mark and free functions.
>
> Data_Wrap_Struct returns a VALUE, which is stored in a variable on the
> stack.
>
> I never leave this function; I call other functions and pass the pointer
> to the structure around, but the variable holding the VALUE stays on the
> stack the entire time.
>
> I am stress-testing QuiXML, so I am deliberately dogging memory to get
> the GC to invoke naturally.
>
> At some point, a rb_str_new() call causes the GC to kick in because
> right then, the free callback for my structure gets called.
>
> Now, from what I understand, since the VALUE associated with the
> structure is still on the stack, the GC was supposed to see it and
> automatically mark it so my structure won't get freed prematurely.
>
> So why did it not get marked? Why was free called?
Is there any difference if you declare the VALUE to be volatile?
--
_ _
| |__ __ _| |_ ___ _ __ ___ __ _ _ __
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
The only other people who might benefit from Linux8086 would be owners
of PDP/11's and other roomsized computers from the same era.
-- Alan Cox