brisk
brisk copied to clipboard
Objective-C: Memory management; tracking object lifetime
We have a sort of simple situation with our objective C bindings. Even though objc uses reference counting we only need to modify reference count twice; increase when we create an object (somewhere in nativeComponent's make) and decrement it when we dispose it possibly in deleteNode. I tend to think we should explicitly release objects when we no longer want them and expect all objects to be retained on the objc side before handing them to OCaml.
BriskToolbar is a good example of a trickier case. https://github.com/briskml/brisk/blob/master/renderer-macos/lib/stubs/BriskToolbar.c#L116
cc @manuhornung who has similar problems in Revery.
The approaches I learned about here should apply in a very similar way to ref-counted Objective-C as they do for C++ smart pointers, so I'm leaving this here for reference
https://discuss.ocaml.org/t/wrapping-c-std-shared-ptr-and-similar-smart-pointers/3582