I see. No, that is not how it works, the user needs to manually handle 
memory management for all Objective-C objects, calling Release() on objects 
that are manually allocated and no longer used, and calling Retain() to 
take ownership of objects that need to be kept. In many contexts (e.g. 
NSApplication callbacks), the Objective-C runtime provides an autorelease 
pool, so there will not need to be too much manual memory management -- 
object constructors provided by the binding automatically call 
"autorelease" before returning pointers to Go, so any temporary objects 
created during a callback should be freed automatically without any need to 
call Retain() or Release().

That said none of this has been thoroughly tested and I'm not entirely sure 
what a good test environment would look like for something like this. If 
you want to see what happens if you do it wrong, you can at least comment 
out the "Retain" calls in the examples and watch them crash.

On Friday, May 31, 2019 at 9:15:41 PM UTC-4, robert engels wrote:
>
> What I meant was that the refs should be treated like any Go object 
> instance, and when collected on the Go side it should dec the ref count so 
> the object can be freed on the OSX side.
>
> Might be tricky with weak refs, etc.
>
> Is that what happens?
>
> On May 31, 2019, at 11:33 AM, Greg Pomerantz <gmp....@wow.st <javascript:>> 
> wrote:
>
> Also I don't think an API is going to assume or require ARC -- as far as I 
> understand it, ARC is just a compiler shortcut that adds retain and release 
> calls so the programmer doesn't have to, it is not any sort of runtime 
> memory management or garbage collection system. As long as Clang has a 
> -fno-objc-arc flag, there should be no problem turning ARC off.
>
> On Friday, May 31, 2019 at 11:51:01 AM UTC-4, Robert Engels wrote:
>>
>> Isn't a lack of ARC support a critical limitation, as ARC is required 
>> going forward, and many of the newer API's assume ARC behind the scenes?
>>
>> -----Original Message----- 
>> From: Greg Pomerantz 
>> Sent: May 30, 2019 8:25 AM 
>> To: golang-nuts 
>> Subject: [go-nuts] Announcing NSWrap -- a comprehensive Objective-C 
>> binding generator for MacOS 
>>
>> I have been working on a binding generator that can read MacOS header 
>> files and provide bindings for Objective-C interfaces and library 
>> functions. NSWrap can also automatically generate classes implementing one 
>> or more named protocols or subclassing a specified class.
>>
>> The automatically generated Go types implement method inheritance, and 
>> overloaded method names are disambiguated. Variadic functions and methods 
>> are supported and pointers to pointers are converted into slices. You can 
>> create selectors (to assign actions to NSControl objects, for example) and 
>> access Objective-C memory management methods (other than Automatic 
>> Reference Counting), including AutoreleasePools.
>>
>> An example Cocoa application is provided in 24 lines of Go code. A 
>> text-mode Bluetooth Low Energy heart rate monitor in pure Go is 127 lines. 
>> The official git repository is linked below. This is the first release, so 
>> expect plenty of rough edges.
>>
>> https://git.wow.st/gmp/nswrap
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golan...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/15be0140-b994-4692-9062-4792be74a8f9%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/15be0140-b994-4692-9062-4792be74a8f9%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>>
>>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golan...@googlegroups.com <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/5ff1a68f-c379-4ea7-9177-1a4e15f899a9%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/5ff1a68f-c379-4ea7-9177-1a4e15f899a9%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/29b141d8-b41f-4f5f-bfb2-9761fef4591d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to