Fix double refs of callback arguments #327

Merged
jwharm merged 1 commit from fix-callback-refs into main 2026-02-12 21:28:21 +01:00
jwharm commented 2026-02-12 21:27:40 +01:00 (Migrated from github.com)

Callback arguments with transfer-ownership=none are ref-ed by java-gi to prevent a double free. However, the call to GObject.ref() was executed every time the callback is executed, continously increasing the refcount. As a result, the objects were never disposed.

This PR introduces a new method InstanceCache.refOnce() that uses an internal Set to ensure the ref() call only happens once for each object.

Callback arguments with transfer-ownership=none are ref-ed by java-gi to prevent a double free. However, the call to `GObject.ref()` was executed every time the callback is executed, continously increasing the refcount. As a result, the objects were never disposed. This PR introduces a new method `InstanceCache.refOnce()` that uses an internal Set to ensure the `ref()` call only happens once for each object.
Sign in to join this conversation.
No description provided.