On 2017-12-13 16:07, Jacob Carlborg wrote:
On 2017-12-13 13:18, mrphobby wrote:

Would it be possible to somehow hook this up automatically to the D destructor perhaps? Interested in hearing your thoughts on this!

As far as I know, the destructor is only called (automatically by the GC). Since the Objective-C objects are not created using the GC the destructor will never be called. I don't think it's possible to implement reference counting (that would call retain/release) for classes in D, since it's not possible to overload the assignment operator for classes [2] or implement a postblit [3]. The only option, as far as I know, would be to wrap the class in a struct that calls retain/release automatically. But then you need to box/unbox the wrapped class constantly and all the method signatures would probably need to use this wrapper as well.

I forgot to mention that there have been several discussions around adding support for reference counted classes. Several of the mentioning interfacing with Objective-C is important/a requirement.

https://wiki.dlang.org/Language_design_discussions#Automatic_Reference_Counting_.28ARC.29_as_an_alternative_to_D.27s_Garbage_Collector

http://forum.dlang.org/post/n0nnu0$1tth$1...@digitalmars.com

https://wiki.dlang.org/FatPointer#Interfacing_with_Objective-C

--
/Jacob Carlborg

Reply via email to