我正在使用touchxml来解析以下方式:

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:@"&nbsp;" withString:@" " options:0 range:NSMakeRange(0, [tempString length])];
[tempString replaceOccurrencesOfString:@"&nbsp" withString:@" " options:0 range:NSMakeRange(0, [tempString length])];

return [tempString autorelease];

}

有帮助吗?

解决方案

当您至少有一个泄漏 [[direction stringValue] isEqualToString:@""] 当您脱离for循环而不释放AutoreLeasePool时,是真的。除此之外,我们还需要查看您的实施 AbfahrtszeitResult 班上看看你的 Linie 定义了设置器。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top