I’m using SudzC as an objective-c wrapper for my xml web services, as you know, SudzC uses TouchXML which is considered one of the best and fastest xml parsers. When loading my xml web service, parsing it and finally saving it to core data, it produces around 2500 records in the database so it is kind of a big service. I noticed something weird, is soap.m file i placed NSLog statement in the following method:
+ (CXMLNode*) getNode: (CXMLNode*) element withName: (NSString*) name {
for(CXMLNode* child in [element children]) {
if([child respondsToSelector:@selector(name)] && [[child name] isEqual: name]) {
return (CXMLNode*)child;
}
}
for(CXMLNode* child in [element children]) {
CXMLNode* el = [Soap getNode: (CXMLElement*)child withName: name];
if(el != nil) { return el; }
}
return nil;
}
and noticed that it’s called 2,180,000 times, awesome number !!!
and the children method mentioned above would definitely be called the same big number too, the children method is defined in CXMLNode.m file of TouchXML as follows:
- (NSArray *)children
{
NSAssert(_node != NULL, @"TODO");
NSMutableArray *theChildren = [NSMutableArray array];
xmlNodePtr theCurrentNode = _node->children;
while (theCurrentNode != NULL)
{
CXMLNode *theNode = [CXMLNode nodeWithLibXMLNode:theCurrentNode];
[theChildren addObject:theNode];
theCurrentNode = theCurrentNode->next;
}
return(theChildren);
}
so you may imagine how much loops are going on here, however, I ran the app, and noticed that my app crashes (due to low memory) after using this web service and doing some specific actions, but if I do these specific actions (in my app) without using the web service, my app will not crash at all, giving that there is no memory leak or memory related problems in my code.
my request is to use the app with the web service without suffering from crashes..
any suggestions would be highly appreciated to solve this problem.
You are creating some autoreleased objects each time through this code such as the array returned by the
childrenmethod. These are not released until you drain the autorelease pool they are created in. Typically this is done for you the next time through the run loop. However, if create a lot of autoreleased objects inside a tight loop like it seems you are doing you will need to create your own autorelease pool inside the loop. Where makes the most sense to do this depends on the details of your code. Apple’s documentation has a discussion about using local autorelease pools to reduce peak memory footprint. Note, this documentation still refers to creatingNSAutoreleasePoolobjects instead of the more modern@autoreleasepool {}.