Hi,
I'm trying to clean my app from leaks with Leak instrument. It shows me leaks on xml parser (TBXML).
Here is a class I'm going to create upon the parsing:
@interface GraphPoint : NSObject {
NSString* x;
NSString* y;
}
@property (nonatomic, copy) NSString* x;
@property (nonatomic, copy) NSString* y;
@end
@implementation GraphPoint
@synthesize x, y;
... some calculations
- (void) dealloc
{
[x release];
[y release];
[super dealloc];
}
@end
In the parser:
... // When found according element:
NSString *str;
GraphPoint *aPoint = [[GraphPoint alloc] init];
TBXMLElement *item = [TBXML childElementNamed:kX_Item parentElement:pntItem];
str = [TBXML textForElement:item];
aPoint.x = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
item = [TBXML childElementNamed:kY_Item parentElement:pntItem];
str = [TBXML textForElement:item];
aPoint.y = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[points addObject:aPoint];
[aPoint release];
Leaks instrument shows leak in TBXML's textForElement function, which provides autoreleased string:
+ (NSString*) textForElement:(TBXMLElement*)aXMLElement {
if (nil == aXMLElement->text) return @"";
return [NSString stringWithCString:&aXMLElement->text[0] encoding:NSUTF8StringEncoding];
}
Since we're talking sometimes about hundreds or even thousands of points, these leaks become something huge. I cannot understand why autoreleased string produce leaks?
Any thoughts?
Thanks