Is the facility free / released on dealloc and / or release?

I recently received an objective-c test to see how I will do.

It turns out my account was nowhere near as I hoped. This means more study.

During the test, I was asked this question:

How do you free an object?

and. [obj dealloc]; B. [obj release]; C. None of the above

My choice was A, and I do not know if this is correct. The question is confused: does not release the call to dealloc, so does it achieve the same result?

+3
source share
3 answers

No. releasedecreases the object reference count.

dealloc . release, dealloc, .

+7

, release dealloc, , . NSObject , release:

"Decrements the receiver’s reference count."  

"The receiver is sent a dealloc message when its reference count reaches 0."
0

, , .

C. , , , .

If you release an object in a reference-counting environment, you will not release it by simply stating that you are waiving any claims of ownership. When no one has ownership, dealloc is called by the runtime and the object is freed. Similarly, in a garbage collection environment, when you rewrite a link, you signal that it is no longer interested. After all the links are gone, after some indefinite time, finalization is sent to the object, and the object is freed.

0
source

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


All Articles