I m actually doing parsing at the start of my program and this is my parser.m class i found "leak" in this class in method "foundCharacters" in line
现有要素 价值 = [[SPStating alloc] initWithString:string];
现有要素 数值为NSMutable 页: 1
NSMutableString *currentElementValue;
Can any one suggest me the way to solve this leak which some times crash my app in the starting...
Thanks In Advance...
事实 方法:-
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"posts"]) {
appDelegate.newsArray = [[NSMutableArray alloc] init];
}
else
{
if([elementName isEqualToString:@"page"])
{
aNewsInfo = [[NewsInfo alloc] init];
aNewsInfo.page = [[attributeDict objectForKey:@"id"] integerValue];
}
if(![elementName compare:@"smallimage"])
{
currentElementValue = [NSMutableString string];
}
if(![elementName compare:@"largeimage"])
{
currentElementValue = [NSMutableString string];
}
}
NSLog(@"Processing Element :%@",elementName);
}
Leak 发现 特征方法:一行。
现有要素 价值 = [[SPStating alloc] initWithString:string];
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!currentElementValue)
现有要素 价值 = [[SPStating alloc] initWithString:string];
else
[currentElementValue appendString:string];
NSLog(@"Processing Value: %@", currentElementValue);
}
采用的方法:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"posts"])
return;
if([elementName isEqualToString:@"page"]) {
[appDelegate.newsArray addObject:aNewsInfo];
NSLog(@"%d",[appDelegate.newsArray count]);
NSLog(@"%@",aNewsInfo.title);
NSLog(@"%@",aNewsInfo.fulltext);
[aNewsInfo release];
aNewsInfo = nil;
}
else {
if ([elementName isEqualToString:@"smallimage"])
{
NSURL *url = [NSURL URLWithString:currentElementValue];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:data];
[aNewsInfo setSmallImageData:image];
}
if(![elementName compare:@"largeimage"])
{
NSURL *imageURL = [NSURL URLWithString:currentElementValue];
NSData *data = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [[UIImage alloc] initWithData:data];
[aNewsInfo setLargeImageData:image];
[image release];
}
[aNewsInfo setValue:currentElementValue forKey:elementName];
[currentElementValue release];
currentElementValue = nil;
}
}