Objective-C save account in dealloc

I see something rather strange here, I have control points set in different methods deallocin my application, and when checking the object hold values selfchange from 1 to 0. When dealloc, will the object hold value be set to 0 already?

I use print (int) [self retainCount]the console to check this out.

It seems that 0 only appears in deallocmine NSOperation, which are executed in NSOperationQueue.

Any idea why this is?

+3
source share
2 answers

Holding your object does not matter in -dealloc. For practical purposes its undefined.

- . NSIncrementExtraRefCount() NSDecrementExtraRefCountWasZero(). extraRefCount , refCount . NSDecrementExtraRefCountWasZero(), extraRefCount , YES -dealloc. , NSDecrementExtraRefCountWasZero(), refCount refCount .

, NSOperation refCount, , .

+8

, objective-c , dealloc, , count count 0, . , saveCount 2, [obj release] , dealloc - , , ,

, NSObject, [super dealloc] dealloc.

-1

Source: https://habr.com/ru/post/1747763/


All Articles