1, block is a property of the Controller object, the use of self inside the block will cause the loop application
void (^testblock) (); @interface Secondviewcontroller () @property (nonatomic, copy) Testblock Testblock; @end = ^() { NSLog (@ "%@", Self.mapview); }; Self.testblock ();
2, the block inside out as a self method, when using Weakself call this method, and this method has the property of self, block does not cause memory leaks
Self.testblock = ^() { [weakself test];}; -(void) test{ NSLog (@ "%@", Self.mapview);}
3. When the block is not a property of self, the use of self within the block does not cause a memory leak
Testblock Testblock = ^() { NSLog (@ "%@", Self.mapview);}; [Self test:testblock];
4, when using the block as a parameter to use, the block internal use of self also does not cause memory leaks
- (void) viewdidload {[Super viewdidload]; [Self getData:^ (NSString *str) {NSLog (@"%@----%@", self, str); }]; [ Selfclass] getdata:^ (NSString *str) {NSLog (@"class method--%@---%@", self, str); }];}- (void) GetData: (successblock) success{if(Success) {Success (@"Success"); }}+ (void) GetData: (successblock) success{if(Success) {Success (@"Success"); }}
Block circular reference problem in iOS