• 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: Bill Bumgarner <email@hidden>
  • Date: Tue, 18 Mar 2003 11:55:55 -0500

On Tuesday, Mar 18, 2003, at 11:39 US/Eastern, email@hidden wrote:
... analysis deleted ...
- (IBAction)MyLoop:(id)sender
{
int i;
xArray = [NSMutableArray array];

for ( i = 0; i < 500000; i++ )
{
NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc] init];
[xArray addObject:[NSString stringWithFormat: @"Don't leak, step
%d", i]];
[myPool release];
}
[xArray removeAllObjects];
return;
}

The release pool in the above code doesn't actually do anything (except slowing down the code)!

The @"..." format string is statically allocated; there should be only one.

The string instance produced by -stringWithFormat: is autoreleased into myPool, by you shove it into an array inside of myPool's scope. This ensures that the string is persisted beyond the call to -release on myPool.

If you were to remove the allocation of myPool, you will likely see a reduction in the memory usage because of fewer object creation/deletion events to potentially fragment the heap.

b.bum
_______________________________________________
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: Lorenzo Puleo <email@hidden>
    • Re: NSAutoreleasePool: how does it really work?
      • From: Lorenzo Puleo <email@hidden>
  • Prev by Date: Re: From 256M to 768M and still paging a lot
  • Next by Date: [OT] A Visual Guide to the User Interface
  • Previous by thread: Re: NSAutoreleasePool: how does it really work?
  • Next by thread: Re: NSAutoreleasePool: how does it really work?
  • Index(es):
    • Date
    • Thread