15 messages in net.java.dev.jna.usersOverride Pointer.finalize to reclaim ...
FromSent OnAttachments
bb...@cox.netJun 26, 2007 9:11 am 
Timothy WallJun 26, 2007 12:52 pm 
Wayne MeissnerJun 26, 2007 7:43 pm 
Ben ChaseJun 26, 2007 8:39 pm 
Wayne MeissnerJun 26, 2007 10:33 pm 
Timothy WallJun 27, 2007 5:08 am 
Timothy WallJun 27, 2007 5:20 am 
Rick GoldsteinJun 27, 2007 8:50 am 
Timothy WallJun 27, 2007 9:59 am 
Ben ChaseJun 27, 2007 7:26 pm 
Timothy WallJun 28, 2007 3:56 am 
bb...@cox.netJun 28, 2007 4:43 am 
bb...@cox.netJun 28, 2007 5:37 am 
bb...@cox.netJun 28, 2007 6:18 am 
Wayne MeissnerJun 28, 2007 7:41 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:Override Pointer.finalize to reclaim Native resources?Actions...
From:bb...@cox.net (bb@cox.net)
Date:Jun 26, 2007 9:11:55 am
List:net.java.dev.jna.users

I'm just starting out with JNA. I need to call a .dll. Here's roughly what the
code looks like so far: // media = (Media) Native.loadLibrary("media",Media.class) PointerByReference phi = new PointerByReference(); media.createHandle(phi); Pointer ih = phi.getValue(); media.readImage(ih); media.frobImage(ih); ... media.destroyHandle(ih);

I am supposed to destroyHandle(), to reclaim resources. My instinct (which may
be poor, since I'm a little shakey on this) is to just override
Pointer.finalize() in a subclass (call it ImagePointer) and have
ImagePointer.finalize() do "media.destroyHandle(this);". Aside from the problem
of having a ImagePointer.finalize() know about "media", there is the more
immediate problem that I cannot subclass Pointer(), because the ctors are
private to avoid pointer mayhem.

So, how should I ensure that the code always does destroyHandle(ih) when it
drops an "ih" on the floor? Is there a typical way?

Ben, a newbie.