[2015-8-13]
- Block = [globleblock retain]//Block仍在globle
- Block = [stackblock retain]//Block仍在stack
- Block = [globleblock copy]//Block仍在globle
- Block = [stackblock copy]//Block在heap,类型为__NSMallocBlock__
- Block = [mallocblock retain]//Block在heap,类型为__NSMallocBlock__,retainCount始终是1,但内存管理器中仍然会增加,需要谨慎使用
int main(int argc, const char * argv[]) { long (^b1)(NSString *) = ^long (NSString* argc){ return 0; }; int base = 100; long (^b3)(NSString *) = ^long (NSString* argc){ return base+0; }; long ret = b1(@"Yabao"); typedef long (^B)(NSString *); // long (^b2)(NSString *) = [b1 retain]; B b2 = [b3 copy]; B b4 = [b1 copy]; [b2 retain]; long ret2 = b3(@"Harry"); NSMutableArray *first_array = [[NSMutableArray alloc]initWithObjects:@"first",@"second", nil]; NSLog(@"first_array retainCount = %zi",first_array.retainCount); // b2.retainCount;//error Memeber reference base type ‘b‘(aka ‘long (^b1)(NSString *)‘ is not a structure or union) [b2 release];//EXC_BAD_ACCESS // [b2 release];//EXC_BAD_ACCESS [first_array release];
时间: 2024-11-25 11:43:31