brisk icon indicating copy to clipboard operation
brisk copied to clipboard

Objective-C: Memory management; tracking object lifetime

Open wokalski opened this issue 6 years ago • 1 comments

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.

wokalski avatar Mar 29 '19 13:03 wokalski

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

manu-unter avatar Jul 16 '19 08:07 manu-unter