3 ms·
It sounds like you're used to manual reference counting in ObjC, which genuinely is a pain. Swift (and modern ObjC) use automatic reference counting, which is m
by seandougall 10y ago
It sounds like you're used to manual reference counting in ObjC, which genuinely is a pain. Swift (and modern ObjC) use automatic reference counting, which is much more robust and less dependent on autorelease pools. For one thing, class instances get released when they no longer have a strong reference -- so to answer your specific question, you can totally instantiate a class for just one iteration of a loop. Plus, Swift makes much better use of value types, so you're less reliant on heap allocations in the first place.
I personally cringe whenever I have to go back to a GC and relinquish all control over object lifecycle.
- pjmlp 10y ago> I personally cringe whenever I have to go back to a GC and relinquish all control over object lifecycle. I think it is a matter of which language and which GC. A few do offer the possibility to control allocation, and sadly a few others that were good at it died in the late 90's.