We can see the memory management section in OC, where the reference counting section, the EBOOK sample on part 10.5 has been running correctly on part 10.9, for example, the following code:
NSString * str1 = @ "string 1 ";
NSString * str2 = @ "string 2 ";
NSMutableString * mstr3 = [NSMutableString stringWithString: @ "string 3"];
NSNumber * int1 = [NSNumber numberWithInteger: 1800000];
NSNumber * long1 = [NSNumber numberWithLong: 1800000];
NSNumber * double1 = [NSNumber numberWithDouble: 300.0];
NSLog (@ "retain count: str1 = % lx, str2 = % lx, str3 = % lx, int1 = % lx, long1 = % lx, double1 = % lx ",
[Str1 retainCount],
[Str2 retainCount],
[Mstr3 retainCount],
[Int1 retainCount],
[Long1 retainCount],
[Double1 retainCount]);
The running result is:
014-11-07 17:05:22. 128 Demo17 [9620: 303] retain count: str1 = ffffffffffffff, str2 = ffffffffffffff, str3 = 1, int1 = 7 fffffffffffffff, long1 = 7 then, double1 = 1
Program ended with exit code: 0
In the EBOOK, it is correct that constant string objects do not participate in counting, but the actual running result shows that the NSNumber object of the integer type does not seem to participate in counting, and the NSNumber object of the floating point is involved in counting, even if the integer is large, it is not counted. Java used to cache small-number encapsulated objects. All small-number encapsulated objects are not counted. But it does not look like this in OC, because numbers are large enough to cache so many integer objects, right?
What is OC? Continue with the study.
The conclusion is as follows:
1. Constant strings are not counted.
2. Constant integer NSNumber objects are not counted.
3. Other objects participate in the count.
After finishing the work, record the problem ~
Object-C memory management-special case of Object reference count