4 ms·
macOS has had automatic retain counting for the last decade. You have to remember your weak/strong for cycles but that's all. It's preferable over garbage coll
by astrange 7y ago
macOS has had automatic retain counting for the last decade. You have to remember your weak/strong for cycles but that's all.
It's preferable over garbage collection because there are no unexpected pauses/memory scans and it's deterministic.
- inlined 7y agoRE pauses, that’s only due to the system-injected calls to autoReleaseReturnValue and retainReturnValue which work in tandem to do assembly call stack analysis and set an extra register to keep return values out of the release pool. This allows pool runs to happen frequently enough with few objects in them and have smooth latency.
- astrange 7y agoThe autorelease optimization actually regularly breaks, because not even the compiler engineers remember it exists, and it relies on libraries tall-calling -autorelease which they also forget to do. Even without it, there isn't a pausing problem because you can clear the pool at the end of the runloop tick, when the app is idle anyway.
- inlined 7y agoBut if you didn’t had the trick, CPU intensive runloop ticks could create lots of small objects that were put in the pool because they had a 0 refcount as a function returned the value. That’s why we had the ability to write our own pools.