Description
Autorelease is a major pain point for Apple integration, and users of this library in particular. It forces an uncomfortable tradeoff between performance and safety, and is quite prone to memory leaks if the calling application doesn't scope the autorelease pools properly.
Using Apple-controlled compilers (ie the official Swift bindings), there's a good solution in the form of objc_retainAutoreleasedReturnValue. However, there are challenges for us to use it.
-
It's not currently present in the objc bindings.
-
It depends on some very specific magic to work, notably bit patterns in the generated asm for the call to the allocating method. It's not obvious to me the best way to make this robust; it might require upstream support in Rust or possibly some other mechanism to generate the proper asm.
-
The objc infrastructure may be undergoing a split, making it less clear where this would go.
This issue came up in the recent Hacker News discussion of the official C++ Metal bindings. Those bindings also don't have a great story around autorelease (I was hopeful they did and we'd be able to adapt it). See this thread in particular for the autorelease-specific discussion, including very helpful info from @comex.