I use a class member called “soapResults” when connecting to a webservice. I use a parser to parse the xml results (it is a json result inside the web service).
- (void) parser:(NSXMLParser *) parser
didStartElement:(NSString *) elementName
namespaceURI:(NSString *) namespaceURI
qualifiedName:(NSString *) qName
attributes:(NSDictionary *) attributeDict {
NSString *attName = [[NSString alloc]initWithFormat:@"%@Result",methodName];
if ([elementName isEqualToString:attName]) {
if (!soapResults) {
soapResults = [[NSMutableString alloc] init];
}
elementFound = YES;
}
[attName release];
}
Now soapResults is a retain member and released in dealloc. I tried to release this in the connection fail/pass but did not succeed. I also tried not to alloc it at all but then I get empty results…. Any help would be appriciated
Edit:
I also get memory leaks inside the parser:
-(void)parser:(NSXMLParser *) parser
foundCharacters:(NSString *)string {
if (elementFound) {
[soapResults appendString: string];//Memory leak here
}
}
If soapResults is a retain property you should change
To
This releases the old value and retains the new one, avoiding leaks.