haxiomic / haxe-c-bridge

Easily interact with haxe classes from C with an automatically generated C header
MIT License
51 stars 5 forks source link

Refcount for retainHaxeObject ? #52

Open singpolyma opened 8 months ago

singpolyma commented 8 months ago

Right now there is no refcount with retainHaxeObject. That means that if two methods are called which both return the same object (or the same method twice, etc) by different parts of the C code, then one part of the C code calls release the GC may free it even though there is still a reference on the C side.

haxiomic commented 7 months ago

Agree and good catch I think a simple fix could be changing the gcRetainMap from <ptr, Dynamic> to <ptr, { obj: Dynamic, refCount: Int }> https://github.com/haxiomic/haxe-c-bridge/blob/2ae120dfc22c198ec556a2d0e586e5a72eacc23a/HaxeCBridge.hx#L1806

I'm not working on this repo at the moment but would accept patches for this