Fix double ref() in static factory methods #197

Merged
jwharm merged 1 commit from fix-double-ref into main 2025-02-08 10:46:56 +01:00
jwharm commented 2025-02-08 10:46:44 +01:00 (Migrated from github.com)

For named constructors, Java-GI generates a static factory method. This method calls the native constructor function, and then calls InstanceCache.getForType() to wrap it in a Java proxy object with the correct class. Finally, it calls object.ref() on the object, but this is unnecessary because the InstanceCache already added a toggle reference. This will prevent the object from being garbage-collected later, so it's a memory leak. This PR removes the double ref().

For named constructors, Java-GI generates a static factory method. This method calls the native constructor function, and then calls `InstanceCache.getForType()` to wrap it in a Java proxy object with the correct class. Finally, it calls `object.ref()` on the object, but this is unnecessary because the InstanceCache already added a toggle reference. This will prevent the object from being garbage-collected later, so it's a memory leak. This PR removes the double `ref()`.
Sign in to join this conversation.
No description provided.