thanks very much. On Fri, Oct 30, 2009 at 3:39 PM, Kai BrĂ¼ning <li...@kai-bruening.de> wrote:
> > 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 (Cocoa-dev@lists.apple.com) >>> 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: >>> http://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org >>> This email sent to r...@rols.org >>> >> _______________________________________________ >> >> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) >> >> 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: >> http://lists.apple.com/mailman/options/cocoa-dev/lists%40kai-bruening.de >> >> This email sent to li...@kai-bruening.de >> > > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com