依據蘋果的官方文檔https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html
下面寫著應該前往的是這個對象的UINT_MAX, 並且不會釋放, 這個UINT_MAX
最大二進制為(11111111111111111111111111111111)也是十六進制(0xffffffff)
假如你當成有符號數取補碼後輸入就得-1;
假如你當成無符號數就是最大數即:4294967295
2.在X64的機器上輸入是9223372036854775807,int的最大值 在I386的機器上輸入是2.由於NSNumber的numberWithInteger發生的對象是屬於autorelease pool
在協助文檔中
可以看到這麼一句話:
The retainCount method does not account for any pending autorelease messages send to the receiver.
就是說retainCount 關於autorelease音訊發生的的對象,並不牢靠。
3.Donot use this method. (required) You should never use-retainCount, because it never tells you anything useful. 永遠不要用這個辦法,只需恪守alloc,neworcopy以及任何需求分配內存的時分調用release就可以了
參考文檔:
NSString *string = [[NSString alloc] init];
[string retain];
NSLog(@"string = %ld", (unsigned long)[string retainCount]);
NSLog(@"string = %lu", (unsigned long)[string retainCount]);
NSString *string2 = [[NSString alloc] initWithString:@"123"];
NSLog(@"string2 = %ld", (unsigned long)[string2 retainCount]);
NSLog(@"string2 = %lu", (unsigned long)[string2 retainCount]);
NSString *string3 = [NSString string];
NSLog(@"string3 = %ld", (unsigned long)[string3 retainCount]);
NSLog(@"string3 = %lu", (unsigned long)[string3 retainCount]);
NSString *string4 = [NSString stringWithFormat:@"123%@",@"123"];
NSLog(@"string4 = %ld", (unsigned long)[string4 retainCount]);
NSLog(@"string4 = %lu", (unsigned long)[string4 retainCount]);
Test *test = [[Test alloc] init];
[test retain];
[test release];
NSLog(@"test = %lu", (unsigned long)[test retainCount]);
以上代碼的打印:
2016-12-20 17:29:17.103 acm[40218:510858] string = -1
2016-12-20 17:29:17.103 acm[40218:510858] string = 18446744073709551615
2016-12-20 17:29:17.103 acm[40218:510858] string2 = -1
2016-12-20 17:29:17.103 acm[40218:510858] string2 = 18446744073709551615
2016-12-20 17:29:17.104 acm[40218:510858] string3 = -1
2016-12-20 17:29:17.104 acm[40218:510858] string3 = 18446744073709551615
2016-12-20 17:29:17.104 acm[40218:510858] string4 = -1
2016-12-20 17:29:17.104 acm[40218:510858] string4 = 18446744073709551615
2016-12-20 17:29:17.104 acm[40218:510858] test = 1
【iOS 切換到MRC環境下打印 retainCount 一直是-1或許一長串證書】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!