jwharm / java-gi

GObject-Introspection bindings generator for Java
GNU Lesser General Public License v2.1
93 stars 9 forks source link

Rework automatic memory cleanup #62

Closed jwharm closed 1 year ago

jwharm commented 1 year ago

The memory of structs/unions (not GObjects) is automatically released when the Java Proxy object gets garbage-collected. However, multiple Proxy objects referring to the same memory address would cause a double-free. This has been fixed by implementing a simple reference-counting scheme. Every new Proxy object for a memory address increases the refcount. And when a Proxy object is finalized, the refcount is decreased. Only when the refcount becomes 0, the memory is reclaimed.