Is the 'reference returned' NSString
from the methods:
scanString:intoString:
scanCharactersFromSet:intoString:
scanUpToString:intoString:
scanUpToCharactersFromSet:intoString:
in the NSScanner
class owned by the calling instance (retain count of 1 and NOT in the autorelease pool) or the NSScanner
instance (retain count of 1 and in the autorelease pool)?
If it is the later would not the autorelease pool balloon in size if used to iterate over a list?
The value
parameter of
- (BOOL)scanString:(NSString *)string intoString:(NSString **)value;
is an "Indirect parameter" in the sense of Indirect parameters in the Clang ARC documentation:
Indirect parameters
If a function or method parameter has type
T*
, whereT
is an ownership-unqualified retainable object pointer type, then:
- if T is const-qualified or Class, then it is implicitly qualified with __unsafe_unretained;
- otherwise, it is implicitly qualified with
__autoreleasing
.
The second case applies here. And __autoreleasing
means:
For
__autoreleasing
objects, the new pointee is retained, autoreleased, and stored into the lvalue using primitive semantics.
So value
points to an autoreleased object upon return from that function.
The Xcode autocompletion "knows" this and shows
[scanner scanString:(NSString *) intoString:(NSString *__autoreleasing *)]
Added: For "manual reference counting", see Memory Management Policy in the "Advanced Memory Management Programming Guide":
You Don’t Own Objects Returned by Reference
... In these cases, the same rules apply as have already been described. When you invoke any of these methods, you do not create the NSError object, so you do not own it. There is therefore no need to release it, ...