From: Iñaki Baz Castillo on
Hi, if I use "malloc" in a Ruby C function and then call to "rb_raise" (so the
program exists), will the allocated memory be released? (if not I get a memory
leak).
Perhaps Ruby havs a garbage collector for C?

Thanks.

--
Iñaki Baz Castillo <ibc(a)aliax.net>

From: Yukihiro Matsumoto on
Hi,

In message "Re: C extension: "malloc" and "rb_raise""
on Sat, 24 Oct 2009 08:43:32 +0900, Iñaki Baz Castillo <ibc(a)aliax.net> writes:

|Hi, if I use "malloc" in a Ruby C function and then call to "rb_raise" (so the
|program exists), will the allocated memory be released? (if not I get a memory
|leak).

No.

|Perhaps Ruby havs a garbage collector for C?

Ruby GC only handles Ruby objects and memory regions pointed by them.

matz.

From: Iñaki Baz Castillo on
El Sábado, 24 de Octubre de 2009, Yukihiro Matsumoto escribió:
> Hi,
>
> In message "Re: C extension: "malloc" and "rb_raise""
>
> on Sat, 24 Oct 2009 08:43:32 +0900, Iñaki Baz Castillo <ibc(a)aliax.net>
writes:
> |Hi, if I use "malloc" in a Ruby C function and then call to "rb_raise" (so
> | the program exists), will the allocated memory be released? (if not I get
> | a memory leak).
>
> No.
>
> |Perhaps Ruby havs a garbage collector for C?
>
> Ruby GC only handles Ruby objects and memory regions pointed by them.

Thanks for clarify it. So I must use free() before rb_raise().

Regards.

--
Iñaki Baz Castillo <ibc(a)aliax.net>

From: Bertram Scharpf on
Hi,

Am Samstag, 24. Okt 2009, 08:55:11 +0900 schrieb Iñaki Baz Castillo:
> El Sábado, 24 de Octubre de 2009, Yukihiro Matsumoto escribió:
> > In message "Re: C extension: "malloc" and "rb_raise""
> > on Sat, 24 Oct 2009 08:43:32 +0900, Iñaki Baz Castillo <ibc(a)aliax.net> writes:
> >
> > |Perhaps Ruby havs a garbage collector for C?
> >
> > Ruby GC only handles Ruby objects and memory regions pointed by them.
>
> Thanks for clarify it. So I must use free() before rb_raise().

It's surely a matter of taste but I think you should not. Mixing
different allocation methods in one C source file will detain you
from understanding your own code just one month later.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
Still I'm convinced there should be a String#notempty? method.

From: Iñaki Baz Castillo on
El Sábado, 24 de Octubre de 2009, Bertram Scharpf escribió:
> Hi,
>
> Am Samstag, 24. Okt 2009, 08:55:11 +0900 schrieb Iñaki Baz Castillo:
> > El Sábado, 24 de Octubre de 2009, Yukihiro Matsumoto escribió:
> > > In message "Re: C extension: "malloc" and "rb_raise""
> > >
> > > on Sat, 24 Oct 2009 08:43:32 +0900, Iñaki Baz Castillo
<ibc(a)aliax.net> writes:
> > > |Perhaps Ruby havs a garbage collector for C?
> > >
> > > Ruby GC only handles Ruby objects and memory regions pointed by them.
> >
> > Thanks for clarify it. So I must use free() before rb_raise().
>
> It's surely a matter of taste but I think you should not. Mixing
> different allocation methods in one C source file will detain you
> from understanding your own code just one month later.

It's a small piece of C code, no more. Do you mean that I shouldn't use
"malloc"/"free" in a Ruby C extension?

Regards.

--
Iñaki Baz Castillo <ibc(a)aliax.net>