I am trying to copy a string that is passed into a method like so:
-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
NSLog( @"elementName, %@: %i", elementName, [elementName retainCount] ); // rc = 2
if ( currenttag )
[currenttag release];
NSLog( @"currenttag: %i", [currenttag retainCount] ); // rc = 0
//currenttag = [[NSString alloc] initWithString:elementName]; // track current element
[self setCurrenttag:elementName];
NSLog( @"currenttag: %i", [currenttag retainCount] ); // rc = 3
.
.
.
}
setCurrenttag
is a synthesized accessor ( @property (copy)
). My understanding was this would create an entirely new object instead just a reference to elementName
. The above behaves as though it is keeping a reference to elementName
and calling retain. The commented out bit of code shows the same behaviour.
These methods are implementing the NSXMLParserDelegate
protocol, but I do need keep a track of certain element names (but not all).
Is there something I am missing concerning NSString
objects and memory management on the iphone.
Also, as reference, I am running this on the iPhone simulator with XCode 3.6.