I m at my first experiences with iPhone development. I wrote some basic code to test the NSScanner class, and now I was looking into the Leaks tool. It seems that this code is leaking, when in the detailed stack I double-click my last call (before Apple s stuff), the incriminated line is the commented.
Can anyone help me to understand why this is leaking? from a logical point of view the result is what I expect, and I do not formally alloc anything myself (except for the xmlblock variable, which is btw autoreleased), so I would not expect the need to release anything... where I m wrong? :-)
+(NSSet *)extractXMLSectionsWithTag:(NSString *)tag fromString:(NSString *)source firstOnly:(BOOL)firstOnly
{
if (!source)
return nil;
NSScanner *scanner = [NSScanner scannerWithString:source];
NSString *openingToken = [NSString stringWithFormat:@"<%@", tag];
NSString *closingToken = [NSString stringWithFormat:@"</%@>", tag];
NSMutableSet *sections = [NSMutableSet set];
NSCharacterSet *majorChar = [NSCharacterSet characterSetWithCharactersInString:@">"];
while (![scanner isAtEnd]) {
NSString *xmlBlock = [[[NSString alloc] init] autorelease];
[scanner scanUpToString:openingToken intoString:NULL];
[scanner scanString:openingToken intoString:NULL];
[scanner scanUpToCharactersFromSet:majorChar intoString:NULL];
[scanner scanCharactersFromSet:majorChar intoString:NULL];
[scanner scanUpToString:closingToken intoString:&xmlBlock];
if (![xmlBlock isEqualToString:@""]) { // Leaking line
[sections addObject:xmlBlock];
if (firstOnly) {
break;
}
}
}
return [sections copy];
}