On Jul 14, 2017, at 3:50 AM, Jeremy Hughes <moon.rab...@virginmedia.com> wrote: > > I’m still not entirely clear on when autorelease pools are used in Swift. > There is a WWDC video which says that they’re used in code that interfaces > with Objective-C, but Greg Parker’s comments in this thread indicate that > autorelease is also used behind the scenes in native Swift code - except that > in many cases the compiler is able to optimise it out of existence. Apple’s > Swift book doesn’t mention autorelease.
I think the hazard here is that you are trying to build a mental model of when to expect autorelease pools (or autorelease behavior in general) and when not to. Worse, that you might design your code to fit those expectations. I think it's a lot safer to understand how strong/weak/unowned work and go from there. You do the appropriate thing to hang onto an object while you're using it and then do the appropriate thing when you're done with it (which might be as simple as setting a variable to nil). Once you're done with the object, it's somebody else's task to make sure that the right things happen at the right time (that's their right time, not yours). _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com