JNA only allocates native memory for Structure instances, freeing that
memory when the Structure is GC'd. It does so internally for String
arguments, but that's not something you have to worry about normally.
If you point a JNA Structure at native-allocated memory, it will use
that memory to read/write and discard the pointer when the Structure
is GC'd.
You could consider JNA as allocating memory as needed (and managing
whatever memory it allocates based on Java object lifespan). JNA will
use native pointers that you give it, generally leaving that memory
alone w/r/t deallocation, making it your responsibility to feed it
back to native code at some later point for proper disposal.
On May 12, 2008, at 2:12 PM, Jay Walters wrote:
So I guess the bit confusing me is the peer-ing aspect. In java I
will always have an object. Java will allocate it (always me?) and
that object will peer with a native object which sometimes I will
allocate and sometimes will get allocated inside the native code.
Does JNA ever allocate the java objects, or do I always have to do
that?