Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6135175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:26:51+00:00 2026-05-23T17:26:51+00:00

I am trying to parse a an xml file. I am creating an array

  • 0

I am trying to parse a an xml file. I am creating an array of dictionaries and then with these created arrays I am creating array with arrays. I am having memory leaks when I am copying my nsdictionary into array. can any one please help!!
Thanks

enter image description here

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{

if(parseMode == 1){
    //        NSLog(@"found this start tag: %@", elementName);
    if ([elementName isEqualToString:@"Group"]) {
        [tInState removeAllObjects];
    }
    else if ([elementName isEqualToString:@"State_Name"]) {
        tData = [[NSMutableDictionary alloc] init];
        xmlItem = 0;
    }
    else if ([elementName isEqualToString:@"T_Name"]) {
        xmlItem = 1;
    }
    else if ([elementName isEqualToString:@"T_Address"]) {
        xmlItem = 2;
    }
    else if ([elementName isEqualToString:@"T_Ph"]) {
        xmlItem = 3;
    }
}

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{     

if (parseMode == 1) {
    //    NSLog(@"found this end tag: %@", elementName);
    if([elementName isEqualToString:@"T_Info"]) {            
        [tInState addObject:[tData copy]];
        [tData autorelease];
    }
    else if ([elementName isEqualToString:@"Group"]) {
        [tlist addObject:tInState];

    }                      
}

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

if (parseMode == 0) {
    [self addToStateList:string];   
}
else  if (parseMode == 1) {
    //       NSLog(@"found this character: %@", string);
    switch (xmlItem) {
        case 0:               
            [tData setValue:string forKey:@"State_Name"];
            break;
        case 1:               
            [tData setValue:string forKey:@"T_Name"];
            break;
        case 2:               
            [tData setValue:string forKey:@"T_Address"];
            break;
        case 3:               
            [tData setValue:string forKey:@"T_Ph"];
            break;
        default:
            break;
    }        
}

}

Here tInState, tInState are nsmutablearray which I allocated in viewdidload function and released in releaseMemory. I went through the NScopy documents and it says when we use copy the ownership is transferred. I am releasing all my arrays so why is it still causing the problem??

Please help with this.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:26:52+00:00Added an answer on May 23, 2026 at 5:26 pm

    On line 81 you are creating a copy of tData but not releasing it so it is leaking. Instead of creating the copy in the addObject call, assign it to a variable, then pass it to addObject, then release it.

    id temp = [tData copy];
    [tInState addObject:temp];
    [temp release];
    

    Also, I’m assuming that the [tData autorelease] is actually meant to release the copy. If so, that’s not necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm having some troubles trying to parse an XML file and display the results
I'm trying to parse Reddit's XML file with javascript and im having trouble retrieving
I'm trying to parse a xml file and I'm having problems with a really
So I'm trying to parse an xml file: <?xml version=1.0 encoding=utf-8 ?> <Root> <att1
I am beginner in PHP. I am trying to parse this xml file. <relationship>
I have an XML file that I'm trying to parse with Linq-to-XML. One of
I'm trying to fetch and parse an XML-file through JavaScript. I don't control the
I am trying to parse xml file and get no errors but when trying
I am trying to parse one XML file that contains some unicode characters.I tried
I'm trying to parse a XML file, but when loading it simpleXML prints the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.