Interview Questions for iOS and Mac Developers →
(via Instapaper)
in the word of changing,
there're things never change.
In bbum’s famous Blocks Tips and Tricks great examples were shown.
However, things changed a litte bit in ARC.
typedef int(^Blocky)(void);
Blocky b[3];
for (int i=0; i<3; i++) {
b[i] = ^{ return i;};
}
for (int i=0; i<3; i++) {
printf("b %d\n", b[i]());
}
The result is
b 0
b 1
b 2
Looks like blocks are retained correctly. If you dig a little bit deeper you’ll see it was retained automaticaly. Another victory for ARC.
leal "___32-[BlockSamplesTests testExample]_block_invoke_0"-L0$pb(%ecx), %esi
movl L__NSConcreteStackBlock$non_lazy_ptr-L0$pb(%ecx), %edi
.loc 1 19 5 ## /Users/jsa/Developer/BlockSamples/BlockSamplesTests/BlockSamplesTests.m:19:5
Ltmp12:
movl %edi, -64(%ebp)
movl $1073741824, -60(%ebp) ## imm = 0x40000000
movl $0, -56(%ebp)
movl %esi, -52(%ebp)
movl %edx, -48(%ebp)
movl -40(%ebp), %edx
movl %edx, -44(%ebp)
movl %eax, (%esp)
calll L_objc_retainBlock$stub
movl -40(%ebp), %ecx
movl -36(%ebp,%ecx,4), %edx
movl %eax, -36(%ebp,%ecx,4)
movl %edx, (%esp)
calll L_objc_release$stub
Ltmp13:
## BB#3: ## in Loop: Header=BB0_1 Depth=1