I've looked at some disassembly of compiled swift code, and I surprised that there is no autorelease calls.
In objc, compiler insert autorelease calls when some method returns reference counted objects, if that method is not marked with
ns_returns_retained attribute. As far as I know, it is done so to eliminate multiple
release calls in chained property access, for example:
id d = a.b.c; do(d); return; // Compiler generates (pseudocode): $temp1 = a.b; $temp2 = $temp1.c; objc_retain($temp2); // only last member in chain needs to be retained and released do($temp2); objc_release($temp2); return;
But in swift I see behaviour like in objc where every method marked with
let d = a.b.c do(d) return // Compiler generates (pseudocode): $temp1 = a.b $temp2 = $temp1.c do($temp2) swift_release($temp1) // every member in chain needs to be released swift_release($temp2) return
I know that objc behaviour produces less code only for long chains (3 and more, I guess?), that are rarely seen in code, and, also, there is no need for swift arc to be compatible with MRR ObjC code. Probably those facts were considered when implementing swift arc.
If that the case, this is great news, but I didn't find any mention in the web about that glorious elimination of autorelease, autorelease pools and all unpredictability associated with it :)