- if (is_threaded) __CFSpinLock(&__CFGlobalRetainLock);
- lowBits = ((CFRuntimeBase *)cf)->_rc;
- if (0 == lowBits) { // Constant CFTypeRef
- if (is_threaded) __CFSpinUnlock(&__CFGlobalRetainLock);
- return;
- }
- if (1 == lowBits) {
- if (is_threaded) __CFSpinUnlock(&__CFGlobalRetainLock);
- if (__CFOASafe) __CFRecordAllocationEvent(__kCFReleaseEvent, (void *)cf, 0, 0, NULL);
- if (__kCFAllocatorTypeID_CONST == __CFGenericTypeID_inline(cf)) {
-#if defined(DEBUG)
- __CFZombifyDeallocatedMemory((void *)cf);
- if (!(__CFZombieLevel & (1 << 4))) {
- __CFAllocatorDeallocate((void *)cf);
- }
-#else
- __CFAllocatorDeallocate((void *)cf);
-#endif
- } else {
- CFAllocatorRef allocator;
- if (NULL != __CFRuntimeClassTable[__CFGenericTypeID_inline(cf)]->finalize) {
- __CFRuntimeClassTable[__CFGenericTypeID_inline(cf)]->finalize(cf);
- }
- if (__CFBitfieldGetValue(((const CFRuntimeBase *)cf)->_info, 7, 7)) {
- allocator = kCFAllocatorSystemDefault;
- } else {
- allocator = CFGetAllocator(cf);
- (intptr_t)cf -= sizeof(CFAllocatorRef);
- }
-#if defined(DEBUG)
- __CFZombifyDeallocatedMemory((void *)cf);
- if (!(__CFZombieLevel & (1 << 4))) {
- CFAllocatorDeallocate(allocator, (void *)cf);
- }
-#else
- CFAllocatorDeallocate(allocator, (void *)cf);
-#endif
- if (kCFAllocatorSystemDefault != allocator) {
- CFRelease(allocator);
- }
- }
- } else {
- if (0x8000 == lowBits) {
- // Time to remove a bit from the external ref count
- if (0 == _CFDictionaryDecrementValue(__CFRuntimeExternRefCountTable, DISGUISE(cf))) {
- lowBits = 0x07fff;
- } else {
- lowBits = 0x0ffff;
- }
- } else {
- lowBits--;
- }
- ((CFRuntimeBase *)cf)->_rc = lowBits;
- if (is_threaded) __CFSpinUnlock(&__CFGlobalRetainLock);
- if (__CFOASafe) {
- uint64_t compositeRC;
- compositeRC = (lowBits & 0x7fff) + ((uint64_t)(uintptr_t)CFDictionaryGetValue(__CFRuntimeExternRefCountTable, DISGUISE(cf)) << 15);
- if (compositeRC > (uint64_t)0x7fffffff) compositeRC = (uint64_t)0x7fffffff;
- __CFRecordAllocationEvent(__kCFReleaseEvent, (void *)cf, 0, compositeRC, NULL);
- }
- }