• 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
NSAutoreleasePool: how does it really work?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSAutoreleasePool: how does it really work?


  • Subject: NSAutoreleasePool: how does it really work?
  • From: Lorenzo Puleo <email@hidden>
  • Date: Tue, 18 Mar 2003 10:33:19 +0100

I don't understand yet how does NSAutoreleasePool really work.
At the end of the following loop, the "top" command tells me that the Rsize
of my application doesn't decrease anymore. Instead I expect that it should
return to the initial value because I remove all the objects from the
xArray. I get lack of memory all the time. I know that "addObject" retains
the object just added, but, how to free up the memory at the end?

===============================
- (void)MyLoop
{
int i;
xArray = [NSMutableArray arrayWithCapacity:0];
for(i = 0; i < 500000; i++){
NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc] init];
NSString *sourceItem = [[NSString alloc]
initWithFormat:@"Item number %d", i];
[sourceItem autorelease];
[xArray addObject:sourceItem];
[myPool release];
}
[xArray removeAllObjects];
}
===============================



If I use only:
===============================
- (void)MyLoop
{
int i;
xArray = [NSMutableArray arrayWithCapacity:0];
for(i = 0; i < 500000; i++){
[xArray addObject:@"abc"];
}
[xArray removeAllObjects];
}
===============================
it works well: at the end of the loop, the Rsize returns to the initial
value.

Where can I learn more about NSAutoreleasePool? I already read the
documentation, but it seems to be not enough. And what did I do wrong?



Best Regards
--
Lorenzo Puleo
email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSAutoreleasePool: how does it really work?
      • From: Phill Kelley <email@hidden>
    • Re: NSAutoreleasePool: how does it really work?
      • From: Oleg Svirgstin <email@hidden>
  • Prev by Date: Re: web services?
  • Next by Date: Re: Convert Image in NSImage to TIFF/PICT Format
  • Previous by thread: Re: How to capture left & right mouse down?
  • Next by thread: Re: NSAutoreleasePool: how does it really work?
  • Index(es):
    • Date
    • Thread