MemoryCleaner
MemoryCleaner
manages the cleanup of native memory associated with Proxy
objects.
Key Responsibilities
Maintains a cache of all memory addresses associated with
Proxy
objects (exceptGObject
instances).Releases native memory automatically when owned
Proxy
objects are garbage-collected.Supports different cleanup methods:
Boxed Type Cleanup: Uses
g_boxed_free
for specific data structures.Custom Cleanup: Allows specifying a custom cleanup function.
Native Heap Cleanup: Uses
nativeHeap.free
to free memory allocated on the native heap.Fallback Cleanup: Uses
g_free
as a fallback.Enables transferring ownership of native memory to and from native code.
Ownership Semantics
Owned Memory: Automatically cleaned up when the associated
Proxy
object is garbage-collected.Non-Owned Memory: Not automatically cleaned up; must be manually managed or transferred.
Ownership can be managed using takeOwnership and yieldOwnership.
Thread Safety
All operations involving the cache are thread-safe, using a ReentrantLock
to ensure synchronization.
Types
Functions
Configures cleanup for a boxed type using g_boxed_free
.
Sets a custom cleanup function for the specified Proxy
instance.
Configures the memory to be freed from the native heap.
Transfers ownership of the memory to the MemoryCleaner
.
Yields ownership of the memory, preventing automatic cleanup.