On Jan 6, 2009, at 3:08 PM, Albert Strasheim wrote:
I also think it could be useful if one could explicitly call
free() on
a Memory instance instead of relying on the finalizer. This becomes
useful when one is dealing with many large buffers that use up
most of
the available memory.
There used to be an explicit "free" in the original JNA CVS
codebase, but I
removed it because it wasn't referenced internally and made
necessary checks
for validity everywhere. At the time I thought it was a lot
cleaner to not
have to worry about Memory being invalid until it was GCd.
In this case, making an ExplicitlyFreeableMemory class if you need
it keeps
the core implementation simpler.
It seems I can't make this class in my own package because Pointer's
constructors are package-private. I am missing something, or is this
something that could be changed?
Derive from com.sun.jna.Memory. It has a public ctor, so your derived
class can explicitly call "finalize", which is protected.