我正在处理一个应用程序,在该应用程序中,我按顺序获取20个Web服务并将解析后的数据存储到sqlite中。当我检查内存的使用时,它将使用接近100 MB。它对我的应用程序有害吗?请检查此屏幕截图,我是从分配器中获取的。
这里我使用的是XML解析委托代码,请检查一下,如果有任何问题请告诉我,
-(void)parser:(NSXMLParser *)parser didStartElement:(NSMutableString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
element = elementName;
if ([element isEqualToString:@"item"])
{
item = [[NSMutableDictionary alloc] init];
self.section = [[NSMutableString alloc] init];
self.position = [[NSMutableString alloc] init];
self.title = [[NSMutableString alloc] init];
self.auther = [[NSMutableString alloc] init];
self.link = [[NSMutableString alloc] init];
self.snippet = [[NSMutableString alloc] init];
self.description = [[NSMutableString alloc] init];
self.pubdate = [[NSMutableString alloc] init];
self.category = [[NSMutableString alloc] init];
self.guide = [[NSMutableString alloc] init];
self.source = [[NSMutableString alloc] init];
self.enclosure = [[NSMutableString alloc] init];
self.enclosureArray = [[NSMutableArray alloc] init];
self.enclosureUrlASrray = [[NSMutableArray alloc] init];
self.enclosureTitleASrray = [[NSMutableArray alloc] init];
self.enclosureDescriptionASrray = [[NSMutableArray alloc] init];
self.enclosureTypeASrray = [[NSMutableArray alloc] init];
self.enclosureLenghtASrray = [[NSMutableArray alloc] init];
allocate=@"YES";
}
if ([elementName isEqualToString:@"enclosure"])
{
self.enclosureArray = [[NSMutableArray alloc] init];
self.enclosureUrlASrray = [[NSMutableArray alloc] init];
self.enclosureTitleASrray = [[NSMutableArray alloc] init];
self.enclosureDescriptionASrray = [[NSMutableArray alloc] init];
self.enclosureTypeASrray = [[NSMutableArray alloc] init];
self.enclosureLenghtASrray = [[NSMutableArray alloc] init];
}
if ([elementName isEqualToString:@"enclosure_details"])
{
self.enclosureDict = [[NSMutableDictionary alloc] init];
self.enclosureUrl = [[NSMutableString alloc] init];
self.enclosureTitle = [[NSMutableString alloc] init];
self.enclosureDescription = [[NSMutableString alloc] init];
self.enclosureType = [[NSMutableString alloc] init];
self.enclosureLenght = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([element isEqualToString:@"enclosure_url"])
{
[self.enclosureUrl appendString:string];
}
if ([element isEqualToString:@"enclosure_title"])
{
[self.enclosureTitle appendString:string];
}
if ([element isEqualToString:@"enclosure_description"])
{
[self.enclosureDescription appendString:string];
}
if ([element isEqualToString:@"enclosure_type"])
{
[self.enclosureType appendString:string];
}
if ([element isEqualToString:@"enclosure_length"])
{
[self.enclosureLenght appendString:string];
}
if ([element isEqualToString:@"section"])
[self.section appendString:string];
if ([element isEqualToString:@"position"])
[self.position appendString:string];
if ([element isEqualToString:@"title"])
[self.title appendString:string];
if ([element isEqualToString:@"author"])
[self.auther appendString:string];
if ([element isEqualToString:@"link"])
[self.link appendString:string];
if ([element isEqualToString:@"snippet"])
[self.snippet appendString:string];
if ([element isEqualToString:@"description"])
[self.description appendString:string];
if ([element isEqualToString:@"pubDate"])
[self.pubdate appendString:string];
if ([element isEqualToString:@"category"])
[self.category appendString:string];
if ([element isEqualToString:@"guid"])
[self.guide appendString:string];
if ([element isEqualToString:@"source"])
[self.source appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([allocate isEqualToString:@"YES"])
{
if ([elementName isEqualToString:@"section"])
{
[item setObject:[self.section uppercaseString] forKey:@"articleSection"];
}
if ([elementName isEqualToString:@"position"])
[item setObject:self.position forKey:@"articlePosition"];
if ([elementName isEqualToString:@"title"])
{
[item setObject:MainCategoryID forKey:@"category"];
[item setObject:[self.title convertStringToHTML] forKey:@"articleTitle"];
}
if ([elementName isEqualToString:@"author"])
[item setObject:self.auther forKey:@"articleAuthor"];
if ([elementName isEqualToString:@"link"])
[item setObject:self.link forKey:@"articleLink"];
if ([elementName isEqualToString:@"snippet"])
[item setObject:[self.snippet convertStringToHTML] forKey:@"articleSnippet"];
if ([elementName isEqualToString:@"description"])
[item setObject:self.description forKey:@"articleDescription"];
if ([elementName isEqualToString:@"pubDate"])
[item setObject:self.pubdate forKey:@"articlePubDate"];
if ([elementName isEqualToString:@"category"])
[item setObject:self.category forKey:@"articleCategory"];
if ([elementName isEqualToString:@"guid"])
[item setObject:self.guide forKey:@"articleGuide"];
if ([elementName isEqualToString:@"enclosure_details"])
{
[self.enclosureUrlASrray addObject:[NSString stringWithFormat:@"%@%@", self.enclosureUrl,SPECIAL_CHAR]];
[self.enclosureTitleASrray addObject:[NSString stringWithFormat:@"%@%@", self.enclosureTitle,SPECIAL_CHAR]];
[self.enclosureDescriptionASrray addObject:[NSString stringWithFormat:@"%@%@", self.enclosureDescription,SPECIAL_CHAR]];
[self.enclosureTypeASrray addObject:[NSString stringWithFormat:@"%@%@", self.enclosureType,SPECIAL_CHAR]];
[self.enclosureLenghtASrray addObject:[NSString stringWithFormat:@"%@%@", self.enclosureLenght,SPECIAL_CHAR]];
}
if ([elementName isEqualToString:@"enclosure"])
{
[item setObject:self.enclosureUrlASrray forKey:@"url"];
[item setObject:self.enclosureTitleASrray forKey:@"title"];
[item setObject:self.enclosureDescriptionASrray forKey:@"description"];
[item setObject:self.enclosureTypeASrray forKey:@"type"];
[item setObject:self.enclosureLenghtASrray forKey:@"lenght"];
}
if ([elementName isEqualToString:@"item"])
{
[self.responseArray addObject:[item copy]];
self.section=nil;self.position=nil;self.title=nil;self.auther=nil;self.link=nil;self.snippet=nil;self.description=nil;self.pubdate=nil;self.category=nil;self.guide=nil;
self.source=nil;self.enclosure=nil;
self.enclosureUrl=nil;self.enclosureTitle=nil,self.enclosureDescription=nil,self.enclosureType=nil,self.enclosureLenght=nil;
self.enclosureUrlASrray=nil;
self.enclosureTitleASrray=nil;
self.enclosureDescriptionASrray=nil;
self.enclosureUrlASrray=nil;
self.enclosureLenghtASrray=nil;
item=nil;
}
}
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
NSLog(@"error : %@",parseError);
[newHUD setHidden:YES];
newHUD=nil;
// [self noInternetMessage];
if ([_delegate respondsToSelector:@selector(ConnectionMessage:)])
{
[_delegate ConnectionMessage:@"Error Occured When user Download the Data From Server, Please Click Refresh Button."];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
[newHUD setHidden:YES];
newHUD=nil;
// NSLog(@"content Parsing : %@",responseArray);
if ([_delegate respondsToSelector:@selector(receivedResultBOArray:responseStr:)])
{
[_delegate receivedResultBOArray:self.responseArray responseStr:MainCategoryID];
self.section=nil;self.position=nil;self.title=nil;self.auther=nil;self.link=nil;self.snippet=nil;self.description=nil;self.pubdate=nil;self.category=nil;self.guide=nil;
self.source=nil;self.enclosure=nil;
self.enclosureUrl=nil;self.enclosureTitle=nil,self.enclosureDescription=nil,self.enclosureType=nil,self.enclosureLenght=nil;
self.enclosureUrlASrray=nil;
self.enclosureTitleASrray=nil;
self.enclosureDescriptionASrray=nil;
self.enclosureUrlASrray=nil;
self.enclosureLenghtASrray=nil;
self.responseArray=nil;
}
}