i am developing one application.In that i perform the xml parsing and get the 400 questions.For getting these questions i created one class with that question attributes.When the question tag is fired i created one object for that class and saved that attributes information and when the didendelement fired for that class i added that class object into one array.Like this i create an object for every question.When i do like this it will take lot of memory and the process is also slow.If i run this one on background it will take same time.SO please tell me how to do this one with less memory.My parsing code is like
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:@"question"])
{
questions=[[Questions alloc]init];
questions.content=[attributeDict valueForKey:@"content"];
questions.id=[attributeDict valueForKey:@"id"];
questions.answer=[attributeDict valueForKey:@"answers"];
questions.type=[attributeDict valueForKey:@"type"];
questions.markertext=[attributeDict valueForKey:@"marker_text"];
questions.markertop=[attributeDict valueForKey:@"marker_top"];
questions.markerleft=[attributeDict valueForKey:@"marker_left"];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
[qshns addObject:questions];
}
Here qshns is the one array.
There is only one way to occupy less memory, that is just hit XML class just only one time and store it into an array or database in any singleton class. Then use it everywhere you want. Never hit XML class again and again it will occupy your large memory.