深浅拷贝之NSString和NSMutableString

由此可见:

这里说明该NSString类型不存在引用计数的概念

    NSString *str1 = @"one day";

    printf("\n初始化赋值引用计数为::::%lu",str1.retainCount);
    NSString *strCopy1=[str1 retain];
    printf("\n继续retain引用计数为:::%lu",str1.retainCount);
    NSString *strCopy2=[str1 copy];
    printf("\n继续copy后引用计数为::::%lu",str1.retainCount);
    NSString *strCopy3=[str1 mutableCopy];
    printf("\n继续mutableCopy后为:::%lu\n",str1.retainCount);
    
    printf("\n非容器类不可变对象\n原始地址::::::::::%p",str1);
    printf("\nretain复制::::::::%p",strCopy1);
    printf("\ncopy复制::::::::::%p",strCopy2);
    printf("\nmutableCopy复制:::%p\n",strCopy3);

==========

**初始化赋值引用计数为****::::18446744073709551615**
**继续****retain****引用计数为****:::18446744073709551615**
**继续****copy****后引用计数为****::::18446744073709551615**
**继续****mutableCopy****后为****:::18446744073709551615**
****
**非容器类不可变对象**
**原始地址****::::::::::0x1000020a0**
**retain****复制****::::::::0x1000020a0**
**copy****复制****::::::::::0x1000020a0**
**mutableCopy****复制****:::0x100103c40**
NSMutableString
NSMutableString *str2=[NSMutableString stringWithString:@"two day"];
    
    printf("\n初始化赋值引用计数为::::::::::::%lu",str2.retainCount);
    NSMutableString *strCpy1=[str2 retain];
    printf("\n继续retain后引用计数为:::::::::%lu",str2.retainCount);
    NSMutableString *strCpy2=[str2 copy];
    printf("\n继续copy后引用计数为:::::::::::%lu",str2.retainCount);
    NSMutableString *strCpy3=[str2 mutableCopy];
    printf("\n继续mutableCopy后引用计数为::::%lu\n",str2.retainCount);
    
    printf("\n非容器类可变对象\n原始地址::::::::::%p",str2);
    printf("\nretin复制::::::::%p",strCpy1);
    printf("\ncopy复制::::::::::%p",strCpy2);
    printf("\nmutableCopy复制:::%p",strCpy3);
**初始化赋值引用计数为****::::::::::::1**
**继续****retain****后引用计数为****:::::::::2**
**继续****copy****后引用计数为****:::::::::::2**
**继续****mutableCopy****后引用计数为****::::2**
****
**非容器类可变对象**
**原始地址****::::::::::0x1006035f0**
**retin****复制****::::::::0x1006035f0**
**copy****复制****::::::::::0x796164206f777475**
**mutableCopy****复制****:::0x1006037e0**

你可能感兴趣的:(深浅拷贝之NSString和NSMutableString)