Pergunta

The image explain the problem (it isn't absurd??!)

enter image description here enter image description here

enter image description here

Foi útil?

Solução

First of all, the -retainCount method returns an unsigned integer, so it, by definition, cannot be negative. You are printing it in the wrong form, because you wrongly assumed it was a signed integer. It is actually NSUIntegerMax.

Second, -retainCount is not useful in general. Even the documentation says:

Do not use this method. (required)

...

This method is of no value in debugging memory management issues. Because any number of framework objects may have retained an object in order to hold references to it, while at the same time autorelease pools may be holding any number of deferred releases on an object, it is very unlikely that you can get useful information from this method.

Third, classes can override -retainCount and return something custom. This is usually done in classes with custom memory management characteristics, which cannot be described well with a retain count. This is the case here because string objects from string literals are statically allocated, and exist for the whole lifetime of the program. They are not memory-managed. Therefore, they return a bogus retain count of NSUIntegerMax.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top