Note that there are some explanatory texts on larger screens.

plurals
  1. POone more memory leak for iPhone
    text
    copied!<p>aBook is defined in .h </p> <p>xml parser.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @class XMLAppDelegate, Book,ZoneCheck; @interface XMLParser : NSObject { NSMutableString *currentElementValue; XMLAppDelegate *appDelegate; Book *aBook; ZoneCheck *aZonecheck; NSString *keyInProgress; NSMutableString *textInProgress; } - (XMLParser *) initXMLParser; @end </code></pre> <p>xmparser.m</p> <pre><code>- (XMLParser *) initXMLParser { [super init]; appDelegate = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate]; return self; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict { // NSLog(@"fXML DATAT MCLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"); /////////// testing for location based ZONE //NSLog(@"found name"); if ( [elementName isEqualToString:@"Location"]) { aZonecheck=[[ZoneCheck alloc]init]; //NSLog(@"found name"); } ////////////////// if ( [elementName isEqualToString:@"id"]) { //NSLog(@"found rootelement"); appDelegate.books = [[NSMutableArray alloc] init]; //[self parser:xmlParser didStartElement:@"state" attributes:dictionary]; //[self parser:xmlParser didStartElement:@"State" attributes:dictionary]; //aBook = [[Book alloc] init]; //Extract the attribute here. // aBook.name= [[attributeDict objectForKey:@"state"] stringValue]; // aBook.notes=[[attributeDict objectForKey:@"notes"]stringValue]; //[self parser:xmlParser didStartElement:@"State" attributes:dictionary]; return; } **else if ( [elementName isEqualToString:@"restra"] ) { aBook = [[Book alloc] init]; //[abook release] cant do that??? return; }** else if ( [elementName isEqualToString:@"totalResult"] ) { //aBook = [[Book alloc] init]; //NSLog(@"found state tttttttttttt "); return; } if ( [elementName isEqualToString:@"cuisines"]) { // NSLog(@"found FUSSSSS"); if ( [elementName isEqualToString:@"cuisine"] ) { // NSLog(@"found CUSSSSSSSSSSSS "); //elementName=[[NSMutableString alloc] init]; keyInProgress = [elementName copy]; // NSLog(@"CAN YOU SEE THIS",keyInProgress); // This is a string we will append to as the text arrives textInProgress = [[[NSMutableString alloc] init]autorelease]; return; } return; } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if(!currentElementValue) currentElementValue = [[NSMutableString alloc] initWithString:string]; else [currentElementValue appendString:string]; //NSLog(@"Processing Value: %@", currentElementValue); [textInProgress appendString:string]; } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { /////////// testing for locations if ( [elementName isEqualToString:@"Locations"]) { return; } if ( [elementName isEqualToString:@"Location"]) { [appDelegate.zone addObject:currentElementValue]; [aZonecheck setValue:currentElementValue forKey:elementName]; NSUserDefaults *saveZone = [NSUserDefaults standardUserDefaults]; [saveZone setObject:currentElementValue forKey:@"keyToZone"]; return; } ////////////// //NSLog(@"SHKLSHLHLSHLHSLS"); if([elementName isEqualToString:@"id"]) return; //There is nothing to do if we encounter the Books element here. //If we encounter the Book element howevere, we want to add the book object to the array // and release the object. if([elementName isEqualToString:@"restra"]) { [appDelegate.books addObject:aBook]; [aBook release]; aBook = nil; } //if([elementName isEqualToString:@"uniqueId"]) { if ([elementName isEqual:keyInProgress]) { if ( [elementName isEqualToString:@"cuisines"]) { //NSLog(@"found FUSSSSS"); if ( [elementName isEqualToString:@"cuisine"] ) { //[elementName setObject:currentLink forKey:@"cuisine"]; //NSLog(@"found CUSSSSSSSSSSSS "); return; } return; } } else [aBook setValue:currentElementValue forKey:elementName]; [aZonecheck setValue:currentElementValue forKey:elementName]; [currentElementValue release]; currentElementValue = nil; } - (void) dealloc { [aBook release]; [aZonecheck release]; [currentElementValue release]; [super dealloc]; } @end </code></pre> <p><strong>where should i release aBook in didstart or didEnd??/</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload