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

Re: NSAutoreleasePool: how does it really work?


  • Subject: Re: NSAutoreleasePool: how does it really work?
  • From: petite_abeille <email@hidden>
  • Date: Tue, 18 Mar 2003 12:43:08 +0100

On Tuesday, Mar 18, 2003, at 12:20 Europe/Zurich, Lorenzo Puleo wrote:

- (IBAction)MyLoop2:(id)sender
{
int i;
xArray = [NSMutableArray arrayWithCapacity:0];
for(i = 0; i < 500000; i++){
NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc] init];
[xArray addObject:[NSString stringWithFormat:@"Do leak, step %d",
i]];
[myPool release];
}
[xArray removeAllObjects];
}

Any idea?

Your array is retaining your strings. The pool allocation/deallocation inside the loop is frivolous.

If for some reasons you want to micromanage your memory pool, try:

NSAutoreleasePool* aPool = [[NSAutoreleasePool alloc] init];
int count = 500000;
int index = 0;
NSMutableArray* anArray = [NSMutableArray arrayWithCapacity: count];

for ( index = 0; index < count; index++ )
{
[anArray addObject:[NSString stringWithFormat: @"Don't leak, step %d", index]];
}

[aPool release];
_______________________________________________
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.

References: 
 >Re: NSAutoreleasePool: how does it really work? (From: Lorenzo Puleo <email@hidden>)

  • Prev by Date: Re: NSAutoreleasePool: how does it really work?
  • Next by Date: Re: Help Book Problems
  • Previous by thread: Re: NSAutoreleasePool: how does it really work?
  • Next by thread: Re: NSAutoreleasePool: how does it really work?
  • Index(es):
    • Date
    • Thread