Why is the retainCount still 1 after [object release]?

后端 未结 5 1325
Happy的楠姐
Happy的楠姐 2021-01-19 07:13
NSLog(@\"first:%u\",[object retainCount]);
[object release];
NSLog(@\"second:%u\",[object retainCount]);

Output:

first:1
second:1
5条回答
  •  忘掉有多难
    2021-01-19 07:37

    First, retainCount doesn't give you a number you can use. It's meaningless.

    Second, the reason the retainCount is 0 is probably that you try to work with an object that doesn't exist anymore. You're lucky your application doesn't crash, because your accessing invalid memory. Decreasing the retainCount just before deallocating an object is unnecessary, therefore Apple doesn't do it, probably.

提交回复
热议问题