On Thu, Sep 11, 2008 at 1:24 PM, Timothy Wall <twal...@dev.java.net> wrote:
On Sep 11, 2008, at 12:47 PM, Argyn wrote:
well, I figured that when I init my Structure for the first time array
field is Memory, but after the very first call to my native function
it becomes Pointer. why?
does it mean that after I do:
A.array = new Memory(remTerms * size);
and call my native function, somehow the reference to Memory is lost
and CAN be garbage collected?
When your structure is read back after the call, it reads the native value
and replaces your Memory reference with a vanilla Pointer. This leaves the
Memory object available for GC.
This is arguably a bug in JNA, in that it shouldn't replace a field if the
peer pointer value is the same.
The workaround is to keep a separate reference to the Memory object.
sh.t, that's what I was afraid of :( I'm actually running a test for
this work around. I have ArrayList with all my memories.
Can you give me a suggestion as to how to fix the bug properly in JNA
code? I could try it myself.