zoukankan      html  css  js  c++  java
  • [IOS] ARC规则

    有关ARC的背景和概念不做详细说明了,简而言之,使用ARC,程序员不需要再关心对象的生命周期,编译器在编译时会聪明的补上这些代码。

    使用ARC的一些规则:

    1. 不允许调用对象的retain, release, auto-relase, retain count等方法,也不允许通过类似@selector(retain)的方法进行间接调用。

    2. 不允许调用对象的dealloc方法。
       虽然重定义类的dealloc方法是允许的,但不能在其中调用[super dealloc]或任何成员变量的dealloc方法,只允许进行一些善后工作,比如释放某些文件资源。

    3. 在@property声明中,不再允许使用retain, copy, assign等关键字,取而代之的是两个新关键字:strong和weak。

    4. 当结构中包含对象指针时,最好不要使用struct,改为class,因为ARC有可能无法辨识struct中的对象指针。

    5. 不允许使用NSAutoReleasePool对象,取而代之的是@autoreleasepool{}块,例如:

    int main(int argc, char *argv[]){
        @autoreleasepool {
            return UIApplicationMain(argc, argv, nil, NSStringFromClass([MyAppDelegate class]));
    } }

    6. 不允许使用NSZone来申请内存空间。也不允许使用NSAllocateObject,NSDeallocateObject。

     

  • 相关阅读:
    JDBC 精度
    AIX性能监控
    OID View
    Deci and Centi Seconds parsing in java
    SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable
    Linux SNMP oid
    MySQL 监控
    SVN 搭建
    C# 之 继承
    storm单词计数 本地运行
  • 原文地址:https://www.cnblogs.com/every2003/p/2575502.html
Copyright © 2011-2022 走看看