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.