Subject: [ruby-ffi] Struct/ManagedStruct and GC behaviour |
From: Jon |
Date: 12/21/09 2:26 PM |
To: ruby-ffi@googlegroups.com |
Before I add API-ish level doc to http://wiki.github.com/ffi/ffi/structs please double check my FFI::Struct and FFI::ManagedStruct understanding. Please ensure feedback is valid across the impl's. 1) Both FFI::Struct and FFI::ManagedStruct are able to be freed by the Ruby impl's GC. Overall GC semantics are no different that any other Ruby object GC'd by the specific Ruby impl. 2) FFI::ManagedStruct enables one to specify custom cleanup code via a required 'release(ptr)' class method that is guaranteed to be called only once when the instance is GC'd. 3) Neither FFI::Struct nor FFI::ManagedStruct currently provide for deterministic GC-ing (is it valid to call FFI::MemoryPointer#free deterministic GC??) 4) FFI::Struct and FFI::ManagedStruct instances live completely in Ruby heap memory. Or are they effectively proxy objects in Ruby heap that interface and manage their underlying native heap-based structs? This one's likely too impl specific to put in the wiki docs, but I'm still curious :) Thanks, Jon