Subject:
Re: [ruby-ffi] freeing memory after FFI::MemoryPointer.new
From:
Chuck Remes
Date:
1/4/11 2:15 PM
To:
ruby-ffi@googlegroups.com


On Jan 4, 2011, at 2:11 PM, 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.

When a MemoryPointer goes out of scope, the garbage collector will free the native memory. Therefore, you likely still have references to these pointers hanging around since they are not collected. 

You may want to try running your extension under rubinius and/or jruby to see if the leaks persist in those environments. They may also give you more hints as to where the problem is.

If you are running on OSX, you may also want to try using the "leaks" program (command line) which will examine a program's heap and report on all leaks it finds.

cr