Subject:
[ruby-ffi] Re: Struct/ManagedStruct and GC behaviour
From:
rogerdpack
Date:
12/22/09 8:21 AM
To:
ruby-ffi

> 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.

My question is
1) is the "struct's worth of memory" allocated when you call #new

2) when you do struct[:member] = something

does it actually set the bits within the struct right then, or at some
later marshalling time?

> You mean, like this?
> http://kenai.com/projects/jruby/sources/main/content/lib/ruby/1.8/Win...

Ooh.

> I should have added a footnote that just because it *can* be
> collected, there is in fact no guarantee that objects are in fact ever
> collected by the GC.  Depending on the implementation, there might not
> be sufficient ruby/java memory pressure to cause a GC event, so the
> objects are not collected, and the native memory is never freed.

In theory there is a guarantee that it will be collected
"at_exit" [objects with finalizers are all called in an at_exit in
MRI].

> Automated management of native memory is a no-win situation:
> If we have it in FFI core, then people will (ab)use it and rely on it
> when they really should not.

Requiring it always might be a bit stiff...

-r