Package org.bytedeco.javacpp
Class PointerScope
java.lang.Object
org.bytedeco.javacpp.PointerScope
- All Implemented Interfaces:
AutoCloseable
Pointer
objects attach themselves automatically on Pointer.init(long, long, long, long)
to the first PointerScope
found in scopeStack
that they can to based on the classes found in forClasses
. The user can then
call deallocate()
, or rely on close()
to release in a timely fashion all attached Pointer objects,
instead of relying on the garbage collector.-
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
When set to true, the next call toclose()
does not release but resets this variable.When not empty, indicates the classes of objects that are allowed to be attached.private static final Logger
The stack keeping references to attachedPointer
objects.(package private) static final ThreadLocal
<Deque<PointerScope>> A thread-local stack ofPointerScope
objects. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new scope accepting all pointer types and pushes itself on thescopeStack
.PointerScope
(Class<? extends Pointer>... forClasses) InitializesforClasses
, and pushes itself on thescopeStack
. -
Method Summary
Modifier and TypeMethodDescriptionPushes the Pointer onto thepointerStack
of this Scope and callsPointer.retainReference()
.void
close()
Pops frompointerStack
all attached pointers, callsPointer.releaseReference()
on them, unless extended, in which case it only resets theextend
flag instead, and finally removes itself fromscopeStack
.void
Pops frompointerStack
all attached pointers, and callsPointer.deallocate()
on them.Removes the Pointer from thepointerStack
of this Scope and callsPointer.releaseReference()
.extend()
static PointerScope
ReturnsscopeStack.get().peek()
, the last opened scope not yet closed.static Iterator
<PointerScope> ReturnsscopeStack.get().iterator()
, all scopes not yet closed.
-
Field Details
-
logger
-
scopeStack
A thread-local stack ofPointerScope
objects. Pointer objects attach themselves automatically onPointer.init(long, long, long, long)
to the first one they can to on the stack. -
pointerStack
The stack keeping references to attachedPointer
objects. -
forClasses
When not empty, indicates the classes of objects that are allowed to be attached. -
extend
boolean extendWhen set to true, the next call toclose()
does not release but resets this variable.
-
-
Constructor Details
-
PointerScope
public PointerScope()Creates a new scope accepting all pointer types and pushes itself on thescopeStack
. -
PointerScope
InitializesforClasses
, and pushes itself on thescopeStack
.
-
-
Method Details
-
getInnerScope
ReturnsscopeStack.get().peek()
, the last opened scope not yet closed. -
getScopeIterator
ReturnsscopeStack.get().iterator()
, all scopes not yet closed. -
forClasses
-
attach
Pushes the Pointer onto thepointerStack
of this Scope and callsPointer.retainReference()
.- Throws:
IllegalArgumentException
- when it is not an instance of a class inforClasses
.
-
detach
Removes the Pointer from thepointerStack
of this Scope and callsPointer.releaseReference()
. -
extend
-
close
public void close()Pops frompointerStack
all attached pointers, callsPointer.releaseReference()
on them, unless extended, in which case it only resets theextend
flag instead, and finally removes itself fromscopeStack
.- Specified by:
close
in interfaceAutoCloseable
-
deallocate
public void deallocate()Pops frompointerStack
all attached pointers, and callsPointer.deallocate()
on them.
-