`
hxg_2009
  • 浏览: 4637 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
最近访客 更多访客>>
社区版块
存档分类
最新评论

copy和retain

    博客分类:
  • IOS
 
阅读更多
原来简单解释过属性定义(Property) ,并且提起了简单的retain,copy,assign的区别。那究竟是有什么区别呢?

assign就不用说了,因为基本上是为简单数据类型准备的,而不是NS对象们。

Retain vs. Copy!!



copy: 建立一个索引计数为1的对象,然后释放旧对象

retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1



那上面的是什么该死的意思呢?

Copy其实是建立了一个相同的对象,而retain不是:

比如一个NSString对象,地址为0×1111,内容为@”STR”

Copy到另外一个NSString之后,地址为0×2222,内容相同,新的对象retain为1,旧有对象没有变化

retain到另外一个NSString之后,地址相同(建立一个指针,指针拷贝),内容当然相同,这个对象的retain值+1

也就是说,retain是指针拷贝,copy是内容拷贝。哇,比想象的简单多了…
转载:http://liuyujie.lofter.com/post/83b14_c5c92
分享到:
评论

相关推荐

    retain和copy还有assign的区别

    retain和copy还有assign的区别

    @property中的retain,copy,assign区别

    @property中的retain,copy,assign区别

    ios_assign,retain和copy详解

    详细讲解了ios中常用关键字的使用方法的区别,着重讲解了assign,retain,copy之间的区别

    IOS中(assign,retain,copy,weak,strong)的区别以及nonatomic的含义

    IOS中(assign,retain,copy,weak,strong)的区别以及nonatomic的含义 我们在声明@property 属性时,总是要在括号中写上assign、retain、copy、weak、strong中的一个,很多时候,我们仅仅只是按照习惯去写经常写...

    浅析iOS中的浅拷贝和深拷贝(copy和mutableCopy)

    ios提供了copy和mutablecopy方法,顾名思义,copy就是复制了一个imutable的对象,而mutablecopy就是复制了一个mutable的对象。 copy与retain的区别: copy是创建一个新对象,retain是创建一个指针,引用对象计数加1...

    Fast copy(快速拷贝)

    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above ...

    Fastcopy2.08(x32)

    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above ...

    fastcopy快速拷贝工具

    Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright ...

    iOS开发之详谈属性设置readwrite、readonly、retain、copy、assign、nonatomic

    主要介绍了iOS开发之详谈属性设置readwrite、readonly、retain、copy、assign、nonatomic的相关资料,需要的朋友可以参考下

    iOS 面试题

    1.关键字 retain 和 release 的 功能 retain 是对oc对象计数器+1 release是对oc对象计数器-1 减到0就自动调用oc对象的dealloc函数 2.请问关键字 alloc 和 init 的 区别 alloc是分配内存,对象计数器为1 init是...

    ios内存管理之深浅拷贝

    通过对不同类型的对象进行retain和copy进行深浅拷贝详细测试分析

    iPhone开发、ObjectiveC_面试题目

    7、定义属性时,什么情况使用copy,assign,和retain 8、autorelease的对象是在什么时候被release的? 9、这段代码有什么问题,如何修改 10、for (int i = 0; i ; i++) { NSString *string = @”Abc”; ...

    File_实用案例_实现文件拷贝_FileCopy.java

    * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the book (recommended), * visit ...

    4.7秒移动1.7G(fastcopy)

    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above ...

    OC中的@property属性问题

    Retain,copy,assign...

    Objective-C内存管理课件.doc

    Objective-C内存管理课件.docx ,assign,retain,copy

    delphi mqtt客户和服务端

    MQTT 协议实现的消息订阅客户端、消息发布客户端、及消息服务器, Finish Retain *) (* Web Sites http://www.alphaworks.ibm.com/tech/rsmb http://www.mqtt.org Permission to copy and display the MQ Telemetry...

    iOS 对象属性详细介绍

    retain,strong, copy,weak,assign,readonly, readwrite, unsafe_unretained 下面来分别讲讲各自的作用和区别: retain,计数器加1, (增加一个指向内存的指针) 对应release(计数器-1) setter 方法对参数进行 ...

Global site tag (gtag.js) - Google Analytics