Subject:
[ruby-ffi] Re: freeing memory after FFI::MemoryPointer.new
From:
Wayne Meissner
Date:
1/4/11 6:55 PM
To:
ruby-ffi@googlegroups.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.