Frenck
Frenck

Reputation: 6534

App is crashing after loading images

My app is crashing after loading thumbnails. On this line the code is downloading the images (thumbnails)

else if ([tempTagName isEqualToString:@"Unicorn"])
            {   

                bottomIndexPage.unitArr = [[NSMutableArray alloc] init];
                NSArray *tempArr = [tempTagValue componentsSeparatedByString:@","];

                for (int i = 0; i<[tempArr count]; i++) 
                {

                    [bottomIndexPage.unitArr addObject:[[NSString alloc] initWithString:[tempArr objectAtIndex:i]]];

                }

In the output's i do not see any crash message. It needs to load thumbnails but the app is crashing by downloading (90 +- thumbnails)

I think it's something in here

 if (!loadXmlFromWeb)
    {
        xmlTextReaderPtr xmlreader = xmlReaderForMemory([xmlData bytes], 
                                                        [xmlData length], 
                                                        [path UTF8String], nil, 
                                                        (XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA | XML_PARSE_NOERROR | XML_PARSE_NOWARNING));
        [self xmlParseProc:xmlreader];
    }
}

Upvotes: 0

Views: 89

Answers (1)

more tension
more tension

Reputation: 3342

First: this code leaks. Using [[ NSString alloc ] initWithString: s ] returns an allocated object you're responsible for disposing of. In a loop like that, you should use an autoreleased string: [ NSString stringWithString: s ].

But in this case you don't need a new string value at all. The -componentsSeparatedByString: has already prepared the string values for you. You don't even need a loop to insert the values from tempArr. Just do:

[ bottomIndexPage.unitArr addObjectsFromArray: tempArr ];

Upvotes: 1

Related Questions