9 messages in net.java.dev.jna.usersRe: [jna-users] Re: Structure toStrin...
FromSent OnAttachments
ArgynSep 11, 2008 9:30 am 
ArgynSep 11, 2008 9:47 am 
Timothy WallSep 11, 2008 10:24 am 
ArgynSep 11, 2008 10:33 am 
Timothy WallSep 11, 2008 10:59 am 
ArgynSep 11, 2008 11:03 am 
Timothy WallSep 11, 2008 11:14 am 
ArgynSep 11, 2008 11:54 am 
Timothy WallSep 11, 2008 12:12 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Re: Structure toString allocated vs nativeActions...
From:Argyn (jawa@gmail.com)
Date:Sep 11, 2008 10:33:25 am
List:net.java.dev.jna.users

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.