Block callback usage-block callback to prevent memory leakage

Source: Internet
Author: User

Block callback usage-block callback to prevent memory leakage

Block is generally used for callback. For example, we encapsulate the asi for request data. It is much easier to use only block to call data.

If you want to add data to the obtained data, remember not to use the self. (This array) or _ (this array) addObject function.

Because we want to change the external variables inside the block, we need to use the blcok callback before

Statement

_ Weaktypeof (self) wekSelf = self; (here I use wekSelf)

In the block callback code segment, all self. (arrays) are replaced with wekSelf to prevent memory leakage.


Present a piece of code:

_ Weak typeof (self) wekSelf = self;

Self. page = 1;

NSDictionary * dic =@{@ "page": @ (self. page )};

[MyDataServicepostMonopolyGroupListRequest: dic cllback: ^ (id data ){

If ([[data objectForKey: @ "code"] integerValue] = 200 ){

NSArray * content = [[data objectForKey: @ "content"] objectForKey: @ "subject_lists"];

If (content &&! [Content isKindOfClass: [NSNull class]) {

[WekSelf. groupArrremoveAllObjects];

For (NSDictionary * dicin content ){

MYGroup * model = [[MYGroupalloc] initWithJson: dic];

[WekSelf. groupArraddObject: model];

}

Dispatch_async (dispatch_get_main_queue (), ^ {

[_ CircleTableViewreloadData];


[_ Circleheaderpolicmselector: @ selector (endRefreshing) withObject: nilafterDelay: 0.1];

});

}

} Elseif ([[data objectForKey: @ "code"] integerValue] = 1000 ){

}

}];




High score helps C Memory leakage detection

My answers depend on each other. I wonder if you can see them?

Yes, the Report you gave is
1 free blocks
2 normal blocks
3 CRT blocks
4 ignore blocks
5 client blocks
6 maximum memory used by the program at any one time (in bytes)
7 total memory currently used by the program (in bytes)
The above content comes from MSDN, so
The meaning of Largest number used and Total allocations is obvious.
Meaning indicated in Items 6 and 7

Largest number used indicates the maximum memory size used at the same time.
Total allocations indicates the memory size currently in use

Memory leakage

Strcore. cpp is the implementation file of the CString class. Check if there is any new CString but no delete, or if there is a member variable of CString in a new class, there is no delete.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.