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:Timothy Wall (twal@dev.java.net)
Date:Sep 11, 2008 10:24:05 am
List:net.java.dev.jna.users

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.