MemoryCleaner
MemoryCleaner manages the cleanup of native memory associated with Proxy objects.
Key Responsibilities
Maintains a cache of all memory addresses associated with
Proxyobjects (exceptGObjectinstances).Releases native memory automatically when owned
Proxyobjects are garbage-collected.Supports different cleanup methods:
Boxed Type Cleanup: Uses
g_boxed_freefor specific data structures.Custom Cleanup: Allows specifying a custom cleanup function.
Native Heap Cleanup: Uses
nativeHeap.freeto free memory allocated on the native heap.Fallback Cleanup: Uses
g_freeas a fallback.Enables transferring ownership of native memory to and from native code.
Ownership Semantics
Owned Memory: Automatically cleaned up when the associated
Proxyobject 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.