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…]; // ...

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…]; // ...

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.completionHandler =

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

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 named

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…]; // ...

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.completionHandler =

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.completionHandler =

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

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 Kyle Sluder
On Thu, Jan 26, 2012 at 2:44 PM, Conrad Shultz con...@synthetiqsolutions.com 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:

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 con...@synthetiqsolutions.com 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:

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 clearer in the

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 retain

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 like

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 to

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 variable, so

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, the object