开发者

Memory Leak in TouchMXL?

开发者 https://www.devze.com 2023-01-04 12:29 出处:网络
I\'m using TouchXML to parse an XML-stream the following way: CXMLDocument *parser = [[CXMLDocument alloc] initWithXMLString:responseString options:0 error:nil];

I'm using TouchXML to parse an XML-stream the following way:

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];
    }

Now, I always get a memory leak in the "stringValue"-line开发者_JS百科... am I doing something wrong or is it TouchXML?

Thanks a lot,

Stefan

-(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];

}


You have at least one leak when [[direction stringValue] isEqualToString:@""] is true as you break out of the for loop without releasing your AutoreleasePool. Beyond that, we'd need to see the implementation of your AbfahrtszeitResult class to see how your Linie setter is defined.

0

精彩评论

暂无评论...
验证码 换一张
取 消