1 message in net.java.dev.jna.usersRe: JNA: Memory.free()
FromSent OnAttachments
Timothy WallApr 8, 2008 9:37 am 
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: Memory.free()Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Apr 8, 2008 9:37:52 am
List:net.java.dev.jna.users

Please direct questions to the JNA users' list.

You can always map "free" in the C library, e.g.

public interface CLibrary extends Library { public void free(Pointer p); }

The malloc/free internal to Pointer/Memory are for internal use only when JNA needs to allocate/free memory for its own needs. If JNA provides you with memory, it will be automatically freed when the object is GC'd.

In general, you should follow the memory management procedures recommended by the library providing you with the memory.

On Apr 8, 2008, at 12:12 PM, x x wrote:

Hello,

I am using JNA for a very short time now an I have a question: What should I do when I need to free a block of Memory ?

I receive a Pointer from the native code and I want to call the native free()-method on this Pointers 'peer'. There is a free()-method, but it is in the Memory-Class and has protected access.

I have added a free()-method to the Pointer-Class, which seems to work just fine, but can't be the real solution:

public void free() { if (peer != 0) Memory.free(peer); }

Am I the only person needing this or did I overlook something ?

Thanks Tom Blecher