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

后端 未结 5 1264
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:25

    Object can be released but not when you think it will be. Basically, don't look at retainCount. It may not change until the next runloop or at all, it's an implementation detail. You will get a sense for when you need to release and when you don't with experience but until then rely on the clang analyzer.

提交回复
热议问题