Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory Leak with NSXMLParser
    primarykey
    data
    text
    <p>I'm writing an app that uses an NSXMLParser to parse info from a website and then store it in my app. I am releasing the parser that I create in my @finally block but Instruments is still showing it as a memory leak. The app's behavior, aside from this, is perfect. Here's the code:</p> <pre><code>NSXMLParser *myParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; //&lt;--memory leak @try { if (myParser != nil) { [myParser setDelegate:self]; [myParser setShouldProcessNamespaces:NO]; [myParser setShouldReportNamespacePrefixes:NO]; [myParser setShouldResolveExternalEntities:NO]; } [myParser parse]; } @catch (NSException * e) { NSLog(@"%@, %@",[e name], [e reason]); } @finally { [xmlURL release]; [myParser release]; } </code></pre> <p>Any recommendations as to why this is showing up as a memory leak?</p> <p><em><strong></em>**EDIT*<em>*</em>*</strong></p> <p>Below is the delegate method I've implemented in my code:</p> <pre><code>-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementName isEqualToString:@"Cube"]) { if ([attributeDict objectForKey:@"time"]) { NSArray *pathsArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [pathsArray objectAtIndex:0]; NSString *timePlistPath = [NSString stringWithString: [path stringByAppendingString:@"/time.plist"]]; NSString *TimeString = [attributeDict objectForKey:@"time"]; [TimeString writeToFile:timePlistPath atomically:YES encoding:NSUnicodeStringEncoding error:nil]; } if ([attributeDict objectForKey:@"currency"] &amp;&amp; [attributeDict objectForKey:@"rate"]) { NSString *currencyObject = [attributeDict objectForKey:@"currency"]; NSString *rateObject = [attributeDict objectForKey:@"rate"]; [mAryCurrency addObject:currencyObject]; [mAryRates addObject:rateObject]; } } </code></pre> <p>}</p> <p>Could this be the cause of the leak?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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