Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-18-2011, 04:44 PM   #1 (permalink)
r@t
Registered Member
 
Join Date: Jan 2011
Posts: 21
r@t is on a distinguished road
Default NSXMLParser limited performance

Hi, I am using NSXMLParser with XML data from a share point server.

If i download more than ten rows of xml at a time it crashes at AppDelegate.h "EXC_BAD_ACCESS".... in the log it says...

"error while killing target (killing anyway): warning: error on line 2184 of "/SourceCache/gdb/gdb-1708/src/gdb/macosx/macosx-nat-inferior.c" in function "void macosx_kill_inferior_safe()": (os/kern) failure (0x5x)"

Also if i include any of the commented out attributes (see code), with even just one row of xml applied, it will also crash.

I can run to a break point just before the dealloc with 20+ rows (the most i have to test) and all the attributes included and I get NO crash.

When I run "Analyze" there are no leaks.

This is parse 6 in a process of 7 separate parses of xml lists. In the end I will need to parse at least 80 rows in this instance .. can someone tell me what i am doing to cause this?

Thanks.

I have included what code i think is relevant.. if you need more just ask.

Code:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
	//NSLog(@"DONE. Received Bytes: %d", [webData length]);
	//NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
	//NSLog(@"theXML: %@",theXML);
    
    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
    [NSURLCache setSharedURLCache:sharedCache];
    [sharedCache release];
    
    xmlParser = [[NSXMLParser alloc]initWithData:webData];
    [xmlParser setDelegate: self];
    [xmlParser parse];
    
    [webData release];
    
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    [nodeContent appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
    
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{		
    
	currentElement = [elementName copy];
    
	if ([elementName isEqualToString:@"z:row"]) {
        
        currentTitle=[[NSString alloc]init];
        currentTitle =[attributeDict valueForKey:@"ows_Title"]; 
        
        currentDepartment=[[NSString alloc]init];
        currentDepartment =[attributeDict valueForKey:@"ows_Department"];
        // get rid of the stuff at the front
        currentDepartment =[currentDepartment substringFromIndex:3];
        
        currentScope=[[NSString alloc]init];
        currentScope =[attributeDict valueForKey:@"ows_Scope"];
        
        currentFormType=[[NSString alloc]init];
        currentFormType =[attributeDict valueForKey:@"ows_Form_x0020_Type"];
        
        currentSection=[[NSString alloc]init];
        currentSection =[attributeDict valueForKey:@"ows_Section"];
        // get rid of the stuff at the front
        currentSection =[currentSection substringFromIndex:3];
        
        currentVersion=[[NSString alloc]init];
        currentVersion =[attributeDict valueForKey:@"ows_Version_x0020_Number"];
        /*
        currentResponsible=[[NSString alloc]init];
        currentResponsible =[attributeDict valueForKey:@"ows_Responsible"];
        
        currentStatus=[[NSString alloc]init];
        currentStatus =[attributeDict valueForKey:@"ows_Status"];
        
        currentFollowUp=[[NSString alloc]init];
        currentFollowUp =[attributeDict valueForKey:@"ows_Follow_x002d_up_x0020_Required"];
        */
    }
}   

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
    
	if ([elementName isEqualToString:@"z:row"]) {
        
        NSMutableDictionary *tempDict = [[NSMutableDictionary alloc]init];
        
        [tempDict setObject:currentTitle forKey: @"formTitle"];
        [tempDict setObject:currentDepartment forKey: @"formDepartment"];
        [tempDict setObject:currentScope forKey: @"formScope"];
        [tempDict setObject:currentFormType forKey: @"formType"];
        [tempDict setObject:currentSection forKey: @"formSection"];
        [tempDict setObject:currentVersion forKey: @"formVersion"];
        //[tempDict setObject:currentResponsible forKey: @"formVersion"];
        //[tempDict setObject:currentStatus forKey: @"formVersion"];
        //[tempDict setObject:currentFollowUp forKey: @"formVersion"];
        
        NSString *tempFormName = [[NSString alloc] initWithFormat:@"%@",currentTitle];
        
        [mDict setObject:tempDict forKey:tempFormName];
        
        [currentTitle release];
        [currentDepartment release];
        [currentScope release];
        [currentFormType release];
        [currentSection release];
        [currentVersion release];
        //[currentResponsible release];
        //[currentStatus release];
        //[currentFollowUp release];
        [tempDict release];
        [tempFormName release];
    }
    
}

- (void)parserDidEndDocument:(NSXMLParser *)parser {
    
    //save FormTemplate Details in the Documents Directory
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documents = [paths objectAtIndex:0];
    NSString *fullFileName = [NSString stringWithFormat:@"%@/FormData.plist",documents];
    [mDict writeToFile:fullFileName atomically:NO];
    mDict=nil;
    
    //Retrieve File to see how it looks
    NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
    NSString *plistPath = [rootPath stringByAppendingPathComponent:@"FormData.plist"];
    
    NSDictionary *rootDict = [NSDictionary dictionaryWithContentsOfFile:plistPath];
    
    NSMutableString *tempString = [[NSMutableString alloc]init];
    
    for (id key in rootDict) {
        
        [tempString appendString:key];
        [tempString appendString:@", "];
        
    }
    
    NSLog(@"FormData: (%d) %@", [rootDict count],tempString);
    [tempString release];
    
    //Pass to next Method
    SyncUsers *syncUsers = [[SyncUsers alloc] init];
    [syncUsers syncUserData];
    [syncUsers release];
    
    
}

- (void)dealloc {
    
    [accountData release];
    [mDict release];
    [super dealloc];
}

@end
r@t is offline   Reply With Quote
Old 12-18-2011, 07:11 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Considering that you know very little about this language:

Code:
currentScope=[[NSString alloc]init];
currentScope =[attributeDict valueForKey:@"ows_Scope"];
...I'm not sure how you can blame NSXMLParser. You don't know what you're doing. You are simultaneously leaking and over-releasing, so I'd suggest learning memory management before you place blame anywhere else. I'd suggest using properties, too.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 12-19-2011, 11:06 AM   #3 (permalink)
r@t
Registered Member
 
Join Date: Jan 2011
Posts: 21
r@t is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Considering that you know very little about this language:

Code:
currentScope=[[NSString alloc]init];
currentScope =[attributeDict valueForKey:@"ows_Scope"];
...I'm not sure how you can blame NSXMLParser. You don't know what you're doing. You are simultaneously leaking and over-releasing, so I'd suggest learning memory management before you place blame anywhere else. I'd suggest using properties, too.
Thanks for the pointer Brian, you are completely correct i am a "noob", as it is equally painfully apparent you have forgotten you were once.

Not that it really matters but I am not sure where you got "blame NSXMLParser" from the statement "can someone tell me what i am doing to cause this?"... but mate i am grateful anyway, please if you need some help with mastering the English language, or getting a girlfriend... i will be there for you.
r@t is offline   Reply With Quote
Old 12-19-2011, 11:11 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Yeah, really not sure how I got that from the title of the thread. Silly me. But hey, if you want a front row seat on my ignore list, keep it up.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 12-20-2011, 03:39 AM   #5 (permalink)
r@t
Registered Member
 
Join Date: Jan 2011
Posts: 21
r@t is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Yeah, really not sure how I got that from the title of the thread. Silly me. But hey, if you want a front row seat on my ignore list, keep it up.
Just sorted it all out and applied properties as you suggested, working well, nice one, thanks again.
r@t is offline   Reply With Quote
Reply

Bookmarks

Tags
nsxmlparser, parsing, xml

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 397
13 members and 384 guests
7twenty7, AppsBlogger, Creativ, Dalia, David-T, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, teebee74, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:50 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0