zoukankan      html  css  js  c++  java
  • 复习一下property

    在面向对象程序里,一个对象不要直接访问另一个对象内部的数据。所以我们使用accessor methods来进行对象内部的数据交互。

     accessor methods(getters and setters) are used as an abstraction for interacting with the object’s underlying data.

    retain就是MRC版的strong

    The retain attribute is the Manual Retain Release version of strong, and it has the exact same effect: claiming ownership of assigned values. You shouldn’t use this in an Automatic Reference Counted environment.

     

    那么assign就是iOS5版本前的weak

    The assign Attribute

    The assign attribute doesn’t perform any kind of memory-management call when assigning a new value to the property. This is the default behavior for primitive data types, and it used to be a way to implement weak references before iOS 5

    This relinquishes ownership of the object immediately after creating it, but keeps it in memory long enough for the caller to interact with it. Specifically, it waits until the end of the nearest @autoreleasepool{}block, after which it calls a normal release method. This is why there’s always an @autoreleasepool{} surrounding the entire main() function—it makes sure all of the autoreleased objects are destroyed after the program is done executing.

    autorelease实际上只是把对release的调用延迟了,对于每一个Autorelease,系统只是把该Object放入了当前的Autorelease pool中,当该pool被释放时,该pool中的所有Object会被调用Release。对于每一个Runloop, 系统会隐式创建一个Autorelease pool,这样所有的release pool会构成一个象CallStack一样的一个栈式结构,在每一个Runloop结束时,当前栈顶的Autorelease pool会被销毁,这样这个pool里的每个Object(就是autorelease的对象)会被release。那什么是一个Runloop呢? 一个UI事件,Timer call, delegate call, 都会是一个新的Runloop
     
     
    访问器

    Setter methods can have additional side-effects. They may trigger KVC notifications, or perform further tasks if you write your own custom methods.

    weak property自动设置为nil,如果指向的对象dealloc.

    To avoid a dangerous dangling pointer to the memory originally occupied by the now deallocated object, a weak reference is automatically set to nil when its object is deallocated. 

  • 相关阅读:
    泛型接口(C# 编程指南) From MSDN
    不知道是不是心理作用,我怎么觉得在Fedora下写cnblogs比Windows下快。
    VS.NET 2005真是太好用了!
    写了个打字游戏,可是有问题(C#)
    C#多线程测试
    关于继承的一个小程序
    VS.NET 2008 试用
    基本排序算法及分析(二):冒泡排序
    基本排序算法及分析(三):shell排序
    [导入]一维数组输出杨辉三角形
  • 原文地址:https://www.cnblogs.com/studyNT/p/4526042.html
Copyright © 2011-2022 走看看