• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: xml object memory issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: xml object memory issue


  • Subject: Re: xml object memory issue
  • From: Kai BrĂ¼ning <email@hidden>
  • Date: Fri, 30 Oct 2009 08:39:49 +0100


On 30.10.2009, at 08:36, Roland King wrote:

Autoreleased objects are only autoreleased when the pool is drained. It is more than likely that the XMLDocument initWithContentsOfURL makes a lot of temporary objects which end up on the autorelease pool but they won't actually be released until the end of your loop.

Put another pool alloc at the start of your loop before the NSURL alloc and then drain it after you release the xmlDocument - that will ensure all temporaries created during the parse are destroyed.

Or switch to garbage collection. By far the better alternative unless you must support Tiger or iPhone.


Kai


XiaoGang Li wrote:
The piece of code I want to discuss is followed:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
for(int i=0;i<5000;i++)
{
NSURL *inAbsoluteURL = [[[NSURL alloc] initFileURLWithPath:@"the
path to one xml file"] autorelease];
NSError *error = NULL;
NSXMLDocument *xmlDocument = [[NSXMLDocument alloc]
initWithContentsOfURL:(NSURL*)inAbsoluteURL
options:0
error:&error];
//hande my Xpath, and do check work. will not cosume the memory.
[xmlDocument release];
}
[pool drain];
return 0;
}
I used the Instruments to detect the objects created but still live until
the application quit, I also use top command to check the memory usage.
I found a lot of node, element, and other children object still live after
the xmlDocument do release.
I found that the memory usage of this application is increasing rapidly.
Can any one give me a guilde to force the system to dealloc the memory
during the for loop. I need to batch handle a lot of xml files. But after
the application runs for a while,
the system will crash because of no memory.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: xml object memory issue
      • From: XiaoGang Li <email@hidden>
References: 
 >xml object memory issue (From: XiaoGang Li <email@hidden>)
 >Re: xml object memory issue (From: Roland King <email@hidden>)

  • Prev by Date: Re: xml object memory issue
  • Next by Date: Re: xml object memory issue
  • Previous by thread: Re: xml object memory issue
  • Next by thread: Re: xml object memory issue
  • Index(es):
    • Date
    • Thread