Hacker News new | past | comments | ask | show | jobs | submit login

I am freaked out by the line, "Retain and Release methods for working with Objective-C garbage collection".

Do they mean the abandoned GC system Apple tried, or the obsolete manual pool-based system Apple used to use?

Either way, I want ARC instead.




Retain/Release methods would be for manual reference counting, as is traditional in Obj-C/Cocoa.

ARC is a compiler trick in the clang objective-c and swift compilers-- essentially injecting the appropriate retain/release calls for you. You won't get that for free in Go (because, again, it's a compiler feature-- compiled ObjC/Swift code is still calling retain/release just like you would manually), but I'd expect some integration with Go's memory management system so you're not having to make those calls manually. (It looks like that is not here in this particular release, though-- they have retain/release calls in some of their examples.)

Objective-C garbage collection is not a thing any more, and hasn't been for quite some time. Deprecated back in macOS 10.8, and outright removed in more recent versions of the runtime (it was never available on iOS, and was taken out sometime around macOS 10.12 on desktop).


age old problem, i should definitely warn people about memory management implications. what would you put in the readme for this?


Do the BridgeSupport files annotate whether you own returned objects and need to release them? Sprinkling in runtime.SetFinalizer calls based on ownership would be slightly nicer than exposing release/retain.


Manual Reference Counting (aka Manual Retain Release) is obsolete in the sense that there's no reason for most people to use it, but it is still completely supported, and Apple themselves still have huge MRC codebases, including AppKit itself. Automatic Reference Counting (ARC) uses the same underlying reference counting mechanism, it just inserts the retain/release calls for you at compile time. (There's slightly more to it than that, especially around ARC's ability to optimize, but it's not too far off.)

The author has already clarified that Objective-C "garbage collection" wasn't really what he meant, but the distinction between ARC and MRC only makes sense in the context of the ObjC compiler itself. From the "outside", esp. for compiled binaries (like the system frameworks), ObjC classes always just use reference counting.


Last I tried to bind to ObjC APIs through C you needed to use NSAutoReleasePool at some point, and to interact with the GC as the APIs expect.

There was no option to use anything else. Has that changed?


ARC is built on top of the retain/release pool system, but it automates everything from the programmer's point of view so you almost never have to explicitly interact with it.


This works across FFI? How?


It doesn't. ARC is a compile-time operation (in Objective-C/Swift)– if you're not using clang or swiftc, then ARC isn't a thing.


sorry I meant memory management not garbage collection. again they're just convenience methods wrapping those exact methods on NSObject




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: