Regarding memory management in OC: Does the release method first determine the release condition or reduce count by one?

  ios, question

The release method is mainly used for reference counting.
One thing is not sure: in the method, it is first determined whether the release condition is met, if not, then count minus one?
There is also another opposite situation: First, reduce count by one, and then judge whether the release conditions are met? ?

Judging from NSObject’s source code, it is to judge whether the counter reaches the release condition first. if it can be released, it will call dealloc, and if not, it will reduce the counter by 2. However, is there any practical significance in understanding the internal implementation details? Maybe the next version will be changed to another way.

- (oneway void)release
    // 检查计数器
    if (_objc_rootReleaseWasZero(self) == false) {
        // 不满足释放条件,就返回
    // 否则,就执行释放操作
    [self dealloc];

_objc_rootReleaseWasZero(id obj)

    if (OBJC_IS_TAGGED_PTR(obj)) return false;

    SideTable *table = SideTable::tableForPointer(obj);

    bool do_dealloc = false;

    if (OSSpinLockTry(&table->slock)) {
        // 找到这个对象的计数器
        RefcountMap::iterator it = table->refcnts.find(DISGUISE(obj));
        if (it == table->refcnts.end()) {
            // 没找到计数器,返回可以释放
            do_dealloc = true;
            table->refcnts[DISGUISE(obj)] = 1;
        } else if (it->second == 0) {
            // 计数器为0,也返回可以释放
            do_dealloc = true;
            it->second = 1;
        } else {
            // 否则,对计数器减2(因为retain的时候是加2)
            it->second -= 2;
        return do_dealloc;
    return _objc_rootReleaseWasZero_slow(obj);

The complete source code is here: Txt