java.lang.Object
io.github.jwharm.cairobindings.MemoryCleaner
This class keeps a cache of all memory addresses for which a Proxy object was created.
When a new Proxy object is created, a Cleaner is attached to it. When the Proxy
object is garbage-collected, the memory is released using the specified free-func.
When ownership of a memory address belongs elsewhere, the cleaner must not free the
memory. Ownership is enabled/disabled with takeOwnership(MemorySegment) and
yieldOwnership(MemorySegment).
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidfree(MemorySegment address) Run theMemoryCleaner.StructFinalizerassociated with this memory address, by invokingCleaner.Cleanable.clean().static voidRegister the memory address of this proxy to be cleaned when the proxy gets garbage-collected.static voidsetFreeFunc(MemorySegment address, String freeFunc) Register a specialized cleanup function for this memory address.static voidtakeOwnership(MemorySegment address) Take ownership of this memory address: when all proxy objects are garbage-collected, the memory will automatically be released.static voidyieldOwnership(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 instance
-
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.StructFinalizerassociated with this memory address, by invokingCleaner.Cleanable.clean().- Parameters:
address- the memory address to free
-