Re: Converting to ARC and blocks

2016-05-02 Thread John McCall
> On May 2, 2016, at 11:30 AM, Steve Mills wrote: > > On May 02, 2016, at 12:58 PM, John McCall wrote: > > > You don't have to declare something with __block just to use it in a block. > > __block specifically means that the variable will be captured *by > > reference* in the block, meaning t

Re: Converting to ARC and blocks

2016-05-02 Thread Steve Mills
On May 02, 2016, at 12:58 PM, John McCall wrote: You don't have to declare something with __block just to use it in a block. __block specifically means that the variable will be captured *by reference* in the block, meaning that changes to the variable within the block are visible in the orig

Re: Converting to ARC and blocks

2016-05-02 Thread John McCall
> On May 2, 2016, at 10:38 AM, Steve Mills wrote: > I'm working on a project that's had to support older hardware/software until > now, so we can *finally* convert to ARC. Since it's been almost a year since > I've worked on anything that used ARC, I'm a little rusty on some of the > stranger s

Re: Converting to ARC and blocks

2016-05-02 Thread Steve Mills
On May 02, 2016, at 12:45 PM, Steve Mills wrote: I'm working on a project that's had to support older hardware/software until now, so we can *finally* convert to ARC. Since it's been almost a year since I've worked on anything that used ARC, I'm a little rusty on some of the stranger stuff, l

Converting to ARC and blocks

2016-05-02 Thread Steve Mills
I'm working on a project that's had to support older hardware/software until now, so we can *finally* convert to ARC. Since it's been almost a year since I've worked on anything that used ARC, I'm a little rusty on some of the stranger stuff, like __unsafe_retained. Here's a pared down hunk bef

Re: ARC and blocks

2012-01-26 Thread Jeff Kelley
On Jan 26, 2012, at 10:45 PM, Roland King wrote: > > On Jan 27, 2012, at 10:04 AM, Marco Tabini wrote: > >> On 2012-01-26, at 6:09 PM, Jeff Kelley wrote: >> >>> Without ARC, you would use __block to prevent the block from retaining the >>> object and causing the retain cycle. With ARC, however

Re: ARC and blocks

2012-01-26 Thread Roland King
On Jan 27, 2012, at 10:04 AM, Marco Tabini wrote: > On 2012-01-26, at 6:09 PM, Jeff Kelley wrote: > >> Without ARC, you would use __block to prevent the block from retaining the >> object and causing the retain cycle. With ARC, however, the object is >> retained when you put it into the variab

Re: ARC and blocks

2012-01-26 Thread Greg Parker
On Jan 26, 2012, at 6:04 PM, Marco Tabini wrote: > On 2012-01-26, at 6:09 PM, Jeff Kelley wrote: >> Without ARC, you would use __block to prevent the block from retaining the >> object and causing the retain cycle. With ARC, however, the object is >> retained when you put it into the variable, so

Re: ARC and blocks

2012-01-26 Thread Marco Tabini
On 2012-01-26, at 6:09 PM, Jeff Kelley wrote: > Without ARC, you would use __block to prevent the block from retaining the > object and causing the retain cycle. With ARC, however, the object is > retained when you put it into the variable, so to avoid a retain cycle, you > have to declare it l

Re: ARC and blocks

2012-01-26 Thread Roland King
On Jan 27, 2012, at 6:44 AM, Conrad Shultz wrote: > On 1/26/12 1:51 PM, Jan E. Schotsman wrote: >> >> > > The block normally would retain variables it captures from its scope, > including, in this case, myController. Presumably myController would > retain the completionHandler block, ergo a r

Re: ARC and blocks

2012-01-26 Thread Abdul Sowayan
Hi, > So, when myController is nil'ed out, ARC releases it, and it releases > the block in turn. No leaks/abandoned memory. > > A special form of this is the idiom: > > __block id mySelf = self; > > ^{ > [mySelf doSomething]; > } Wouldn't using __weak instead of __block be better and cleare

Re: ARC and blocks

2012-01-26 Thread Conrad Shultz
On 1/26/12 4:21 PM, Kyle Sluder wrote: > On Thu, Jan 26, 2012 at 2:44 PM, Conrad Shultz > wrote: >> However, __block variables are NOT retained automatically by a block >> during capture, so this breaks the retain cycle. > > __block variables *are* retained under ARC: > http://clang.llvm.org/docs

Re: ARC and blocks

2012-01-26 Thread Kyle Sluder
On Thu, Jan 26, 2012 at 2:44 PM, Conrad Shultz wrote: > However, __block variables are NOT retained automatically by a block > during capture, so this breaks the retain cycle. __block variables *are* retained under ARC: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#misc.blocks The i

Re: ARC and blocks

2012-01-26 Thread David Duncan
On Jan 26, 2012, at 2:44 PM, Conrad Shultz wrote: > However, __block variables are NOT retained automatically by a block > during capture, so this breaks the retain cycle. This is not true under ARC, where __block variables also retain. -- David Duncan __

Re: ARC and blocks

2012-01-26 Thread Jeff Kelley
Without ARC, you would use __block to prevent the block from retaining the object and causing the retain cycle. With ARC, however, the object is retained when you put it into the variable, so to avoid a retain cycle, you have to declare it like so: __unsafe_unretained __block MyViewCont

Re: ARC and blocks

2012-01-26 Thread Greg Parker
On Jan 26, 2012, at 1:51 PM, Jan E. Schotsman wrote: > This code is given in the "Transitioning to ARC Release Notes" as an example > of accomodating blocks in an ARC environment: > > __block MyViewController *myController = [[MyViewController alloc] init…]; > // ... > myController.completionHand

Re: ARC and blocks

2012-01-26 Thread Ken Thomases
On Jan 26, 2012, at 3:51 PM, Jan E. Schotsman wrote: > This code is given in the "Transitioning to ARC Release Notes" as an example > of accomodating blocks in an ARC environment: > > __block MyViewController *myController = [[MyViewController alloc] init…]; > // ... > myController.completionHan

Re: ARC and blocks

2012-01-26 Thread Marco Tabini
On 2012-01-26, at 3:51 PM, Jan E. Schotsman wrote: > Hello, > > This code is given in the "Transitioning to ARC Release Notes" as an example > of accomodating blocks in an ARC environment: > > __block MyViewController *myController = [[MyViewController alloc] init…]; > // ... > myController.com

Re: ARC and blocks

2012-01-26 Thread Fritz Anderson
On 26 Jan 2012, at 3:51 PM, Jan E. Schotsman wrote: > This code is given in the "Transitioning to ARC Release Notes" as an example > of accomodating blocks in an ARC environment: > > __block MyViewController *myController = [[MyViewController alloc] init…]; There is a MyViewController object n

Re: ARC and blocks

2012-01-26 Thread Jens Alfke
On Jan 26, 2012, at 1:51 PM, Jan E. Schotsman wrote: > Supposedly this avoids a retain cycle. But where is the cycle? At least two > objects are needed for a cycle. What is the second one? The block. When a block is copied (which it has to be, in order to be called later after the calling func

Re: ARC and blocks

2012-01-26 Thread Conrad Shultz
On 1/26/12 1:51 PM, Jan E. Schotsman wrote: > Hello, > > This code is given in the "Transitioning to ARC Release Notes" as an > example of accomodating blocks in an ARC environment: > > __block MyViewController *myController = [[MyViewController alloc] init…]; > // ... > myController.completionHa

Re: ARC and blocks

2012-01-26 Thread Jean-Daniel Dupas
Le 26 janv. 2012 à 22:51, Jan E. Schotsman a écrit : > Hello, > > This code is given in the "Transitioning to ARC Release Notes" as an example > of accomodating blocks in an ARC environment: > > __block MyViewController *myController = [[MyViewController alloc] init…]; > // ... > myController.

Re: ARC and blocks

2012-01-26 Thread David Duncan
On Jan 26, 2012, at 1:51 PM, Jan E. Schotsman wrote: > Hello, > > This code is given in the "Transitioning to ARC Release Notes" as an example > of accomodating blocks in an ARC environment: > > __block MyViewController *myController = [[MyViewController alloc] init…]; > // ... > myController.c

ARC and blocks

2012-01-26 Thread Jan E. Schotsman
Hello, This code is given in the "Transitioning to ARC Release Notes" as an example of accomodating blocks in an ARC environment: __block MyViewController *myController = [[MyViewController alloc] init…]; // ... myController.completionHandler = ^(NSInteger result) { [myController dism