11 messages in net.java.dev.jna.usersRe: [jna-users] NativeLibrary Usage
FromSent OnAttachments
Christine GrudeckiJul 26, 2007 7:11 am 
Timothy WallJul 26, 2007 8:35 am 
Christine GrudeckiJul 26, 2007 12:52 pm 
Timothy WallJul 26, 2007 1:21 pm 
pzab...@poczta.onet.plJul 27, 2007 8:57 am 
Timothy WallJul 27, 2007 11:24 am 
Timothy WallJul 30, 2007 3:41 am 
Timothy WallJul 30, 2007 7:54 am 
Timothy WallJul 30, 2007 8:58 am 
Christine GrudeckiJul 30, 2007 9:24 am 
Timothy WallJul 30, 2007 10:49 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-users] NativeLibrary UsageActions...
From:Timothy Wall (twal@dev.java.net)
Date:Jul 26, 2007 8:35:36 am
List:net.java.dev.jna.users

On Jul 26, 2007, at 10:11 AM, Christine Grudecki wrote:

Currently, I'm opening and using the library as per the documentation. However, my server is crashing after a few iterations of my program because there is no way to close the library after opening it during each iteration (it runs on a scheduler every 10 minutes). I think I need to be using the NativeLibrary class since it has the Finalize method, but I can't find any documentation or examples of how to use it instead of the Library interface.

Can I use the Library interface in conjunction with the NativeLibrary class? Or are they mutually exclusive? How do I convert the example to use

Here are snippets of my code:

public interface MyLibrary extends Library {

MyLibrary INSTANCE = (MyLibrary) Native.loadLibrary("/usr/local/lib/MyLibrary.so", MyLibrary.class);

This pattern should only be used if you are *not* concerned about the library being closed and disposed. When you use the singleton INSTANCE pattern, the library will remain opened until the MyLibrary interface class object gets GC'd.

In order to enable GC of the library as soon as possible, use a local variable instead of a static instance to hold the result of Native.loadLibrary. You shouldn't need to use NativeLibrary directly; the InvocationHandler for your library interface instance will hold the only reference to the NativeLibrary (the NativeLibrary cache uses weak references), so when the library interface gets GC'd, the corresponding NativeLibrary will also be disposed.