java.lang.Object
io.github.jwharm.cairobindings.MemoryCleaner
This class keeps a cache of all memory addresses for which a Proxy object
was created (except for GObject instances; those are handled in the InstanceCache).
When a new Proxy object is created, the reference count in the cache is increased. When a Proxy object is garbage-collected, the reference count in the cache is decreased. When the reference count is 0, the memory is released using the specified free-func.
When ownership of a memory address is passed to native code, the cleaner will not free
the memory. Ownership is enabled/disabled with takeOwnership(MemorySegment)
and
yieldOwnership(MemorySegment)
.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
free
(MemorySegment address) Run theMemoryCleaner.StructFinalizer
associated with this memory address, by invokingCleaner.Cleanable.clean()
.static void
Register the memory address of this proxy to be cleaned when the proxy gets garbage-collected.static void
setFreeFunc
(MemorySegment address, String freeFunc) Register a specialized cleanup function for this memory address.static void
takeOwnership
(MemorySegment address) Take ownership of this memory address: when all proxy objects are garbage-collected, the memory will automatically be released.static void
yieldOwnership
(MemorySegment address) Yield ownership of this memory address: when all proxy objects are garbage-collected, the memory will not be released.
-
Method Details
-
register
Register the memory address of this proxy to be cleaned when the proxy gets garbage-collected.- Parameters:
proxy
- The Proxy object
-
setFreeFunc
Register a specialized cleanup function for this memory address.- Parameters:
address
- the memory addressfreeFunc
- the specialized cleanup function to call
-
takeOwnership
Take ownership of this memory address: when all proxy objects are garbage-collected, the memory will automatically be released.- Parameters:
address
- the memory address
-
yieldOwnership
Yield ownership of this memory address: when all proxy objects are garbage-collected, the memory will not be released.- Parameters:
address
- the memory address
-
free
Run theMemoryCleaner.StructFinalizer
associated with this memory address, by invokingCleaner.Cleanable.clean()
.- Parameters:
address
- the memory address to free
-