Subject:
Re: [ruby-ffi] Re: freeing memory after FFI::MemoryPointer.new
From:
Alvaro
Date:
1/5/11 7:51 AM
To:
ruby-ffi@googlegroups.com

2011/1/4 Wayne Meissner <wmeissner@gmail.com>:
> On Wednesday, January 5, 2011 6:11:56 AM UTC+10, Alvaro wrote:
>>
>> Hi,
>>
>> I wonder if there is something that needs to be done after call to
>> FFI::MemoryPointer.new
>> to free the memory, my extension has memory leaks and it only happens
>> with the binding
>> and not with the original C lib.
>
> As Chuck says, when the last strong reference to an FFI object is removed,
> it becomes eligible for collection - so you most likely have a persistent
> reference to the memory pointer that is keeping it alive.
> All objects defined in ruby-ffi follow that pattern - they are auto-release
> by default.  You can set autorelease = false on MemoryPointer instances
> which means the memory can _never_ be freed, but that is probably a rare
> occurrence.
> That does not apply to pointers allocated via mapping in say malloc or
> calloc from libc - those have to be manually managed.
>
>
>
>

I understand your point about how it works the garbage collection.
Is a kind strange that the C lib purely don't have leaks but with the
FFI binding it has and I couldn't find the reason yet, may be is
inherited to ruby, I've tested it with Ree, Mri and JRuby without
success.

I will continue trying to figure out what is happening, thanks for
your comments.

-- Alvaro