0
我使用TouchXML解析XML流的方式如下:TouchMXL內存泄漏?
CXMLDocument *parser = [[CXMLDocument alloc] initWithXMLString:responseString options:0 error:nil];
[responseString release];
// array holding all the nodes
NSArray *directionNodes = [parser nodesForXPath:@"//direction" error:nil];
NSArray *linieNodes = [parser nodesForXPath:@"//route" error:nil];
NSArray *timeNodes = [parser nodesForXPath:@"//time" error:nil];
for (int i = 0; i < [directionNodes count]; i++) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CXMLElement *direction = [directionNodes objectAtIndex:i];
CXMLElement *route = [linieNodes objectAtIndex:i];
CXMLElement *time = [timeNodes objectAtIndex:i];
// if rows are empty, stop it
if ([[direction stringValue] isEqualToString:@""]) {
break;
}
AbfahrtszeitResult *result = [[AbfahrtszeitResult alloc] init];
[result setLinie:[route stringValue]];
[result setZiel:[direction stringValue]];
[result setZeit:[time stringValue]];
[mutableAbfahrten addObject:result];
[result release];
[pool release];
}
現在,我一直在「stringValue的」直插......得到了內存泄漏我做錯了什麼或者是它TouchXML?
非常感謝,
斯特凡
-(NSString *) linie {
return linie;
}
- (void) setLinie:(NSString *)textValue {
[textValue retain];
[linie release];
linie = textValue;
}
-(NSString *) ziel {
return ziel;
}
-(void) setZiel:(NSString *)textValue {
[textValue retain];
[ziel release];
ziel = textValue;
}
-(NSString *) zeit {
return zeit;
}
-(void) setZeit:(NSString *)textValue {
[textValue retain];
[zeit release];
zeit = textValue;
}
+ (NSString *) cleanUpString:(NSString *) cleanme {
NSMutableString *tempString = [[NSMutableString alloc] initWithString:cleanme];
[tempString replaceOccurrencesOfString:@" " withString:@" " options:0 range:NSMakeRange(0, [tempString length])];
[tempString replaceOccurrencesOfString:@" " withString:@" " options:0 range:NSMakeRange(0, [tempString length])];
return [tempString autorelease];
}
hi, 我添加了Abfahrtszeitresult(getter和setter)的實現。 你可以忽略NSAutoreleasePool - 當然這是我犯的一個錯誤,但泄漏在我引入池之前就已經存在了。 – swalkner 2010-06-25 04:28:24