当前位置:网站首页>OC-ARC (Automatic Reference Counting) automatic reference counting
OC-ARC (Automatic Reference Counting) automatic reference counting
2022-07-30 10:19:00 【Classmate Peng, she is at the same table】
ZRC Notes
1. Cannot call:
retain, release, autorelease, retainCount, @selector(retain), dealloc
The system will call these automatically
2. Replace NSAutoReleasePool with @autoreleasepool
@autoreleaasepool
{
/* Perform a series of operations * can use break,returen,goto */
}
3. You can rewrite dealloc yourself but don't release the instance object in delloc, you can release some default types such as int, char, FIFE
int *a; FIFE *p; free(a);fclose(p);and don't call [super dealloc];
The conversion between the 4.id type and the void* type cannot be performed, but it can be achieved through the __bridge modifier
5. When compiling, the __autoreleasing modifier will be added to the double pointer variable of the function automatically, for example
-(id)initWithErrir:(NSError **)error;// will be compiled as-(id)initWithErrir:(__autoreleasing NSError **)error;6. It is required that the initial value of the variable must be nil
7. The functions that operate memory such as memset, bzero, memcpy cannot be used. ARC will monitor the behavior of these functions.)
8. When ARC is in effect, OC objects cannot be defined in C language structure questions. The compiler cannot automatically release the OC objects inside the structure. If it must be used, use the __unsage_unretained modifier to modify the OC variables in the structure.The advantage is that the compiler will not care about the memory of this variable at all. The disadvantage is that it needs to be managed manually
If you use the terminal to compile the code, use clang together and add the compile option -fobjc-arc
Method family
Because retain and release are automatically added by the system, the system needs to know which functions are related to object production
Therefore, the collection of methods related to object production is called "method family", which mainly requires special naming rules
SatisfyReturn value, method category
The selector is the same as the method family name (starting with _ can be ignored)
The name of the selector consists of the family name plus a string starting with a non-lowercase letter
Usually init/alloc/beginning of new/copy/mutableCopy
Automatically convert to ARC
edit->Refactor find the widget Convert to Objective-C ARC
Code that uses garbage collection cannot be automatically converted to ARC-enabled code
Macros to manage ARC
The declaration of the macro should be placed at the end of the method
NS_RERTURNS_RETAINED
Indicate that this method is the same as the method at the beginning of init or copy, and the caller is responsible for releasing the returned object
That is, although this function is not an ARC naming ruleBut let him be managed by ARC
NS_RERTURNS_NOT_RETAINED
Indicates that this method is not a memory management method, and the caller does not need to release the returned object
Simply put, this function must not be managed by ARC
For example
-(void)initName NS_RERTURNS_NOT_RETAINED;
Originally, this function with init should be managed by ARC, but after adding NS_RERTURNS_NOT_RETAINED, it is no longer needed
Determine if ARC is valid
Judging by conditional compilation
#if(__has_feature(objc_arc)) is valid if true
边栏推荐
- spark udf 接受并处理 null值.
- 新一代开源免费的终端工具,太酷了
- MySQL |子查询
- Re21: Read the paper MSJudge Legal Judgment Prediction with Multi-Stage Case Representation Learning in the Real
- MFCC转音频,效果不要太逗>V<!
- New in GNOME: Warn users when Secure Boot is disabled
- Detailed explanation of JVM memory layout, class loading mechanism and garbage collection mechanism
- Re15: Read the paper LEVEN: A Large-Scale Chinese Legal Event Detection Dataset
- 死锁的理解
- 自适应控制——仿真实验一 用李雅普诺夫稳定性理论设计自适应规律
猜你喜欢

再有人问你分布式事务,把这篇扔给他

A near-perfect Unity full-platform hot update solution

SST-Calib: A lidar-visual extrinsic parameter calibration method combining semantics and VO for spatiotemporal synchronization calibration (ITSC 2022)

百度推广助手遇到重复关键字,验证错误,怎么一键删除多余的

MFCC转音频,效果不要太逗>V<!

BERT预训练模型系列总结

Re20:读论文 What About the Precedent: An Information-Theoretic Analysis of Common Law

STM32CubeMX配置生成FreeRTOS项目

【HMS core】【Analytics Kit】【FAQ】如何解决华为分析付费分析中付款金额显示为0的问题?

Detailed explanation of JVM memory layout, class loading mechanism and garbage collection mechanism
随机推荐
线程池方式开启线程--submit()和execute()的区别
Paper reading: SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers
Beijing suddenly announced big news in the Metaverse
Domino服务器SSL证书安装指南
快解析结合用友时空
Day113.尚医通:微信登录二维码、登录回调接口
【HMS core】【Analytics Kit】【FAQ】如何解决华为分析付费分析中付款金额显示为0的问题?
Always remember: one day you will emerge from the chrysalis
软考 系统架构设计师 简明教程 | 系统运行与软件维护
元宇宙改变人类工作模式的四种方式
BERT预训练模型系列总结
Practical Walkthrough | Calculate Daily Average Date or Time Interval in MySQL
C语言顺序表基本操作
debian10 install djando
OC-ARC(Automatic Reference Counting)自动引用计数
A new generation of free open source terminal tool, so cool
包、类及四大权限和static
Array of Shell System Learning
flyway的快速入门教程
Matplotlib--plot markers