• 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: Newbie with stupid question cont.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie with stupid question cont.


  • Subject: Re: Newbie with stupid question cont.
  • From: Don Rainwater <email@hidden>
  • Date: Tue, 19 Mar 2002 10:42:08 -0500

On Tuesday, March 19, 2002, at 08:13 AM, Ondra Cada wrote:
On Tuesday, March 19, 2002, at 07:44 , Sam Goldman wrote:
for(x=0 ; x < [ifaces count]; x++){
sReturn = [NSString stringWithFormat:@"%@ (%@)", [ifaces
objectAtIndex:x], [self getIPForInterface:[ifaces objectAtIndex:x]]];
[arrReturn addObject:sReturn];
[sReturn release]
}


And you probably don't want to have a bunch of autoreleased objects in a
loop. The autorelease pool will get really big and slow down your app. If
performance is an issue, then you should avoid autoreleased objects being
created inside of loops which count potentially happen a bunch of times.

Nope. quite the contrary. With a vast majority of loops (depends on other conditions too, but a rough guess might be up to XXX iterations) autoreleasing makes no problem at all, and the slowing down is unnoticeable.

If the loop is to be iterated many times indeed, the solution is still autoreleasing, this time with a local loop:

for (...many times...) {
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
...
[pool release];
}

Seems counter-intuitive, doesn't it? You would think that the overhead involved in this approach would be expensive. Is this a memory allocation issue? Is it because the default pool is of a preset size and extending it incurs a lot of overhead, or because of overall process resource allocations, or...? For a really high loop count, would there be any benefit to something like:

NSAutoreleasePool *pool;

pool = [[NSAutoreleasePool alloc] init];
for (x = 1; x <= highLoopLimit; x++) {
if (!(x % poolLimit)) {
[pool release];
pool = [[NSAutoreleasePool alloc] init];
}
...
}
[pool release];

// where poolLimit is 100, or 1000, or some useful number less than highLoopLimit.

Or am I overthinking this?
--
Don Rainwater, Technology Manager email@hidden
UCit Educational Services
University of Cincinnati
_______________________________________________
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: Newbie with stupid question cont.
      • From: Ondra Cada <email@hidden>
    • Re: Newbie with stupid question cont.
      • From: Shawn Erickson <email@hidden>
References: 
 >Re: Newbie with stupid question cont. (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Learning AppleScript?
  • Next by Date: Re: Need clarification on categories
  • Previous by thread: Re: Newbie with stupid question cont.
  • Next by thread: Re: Newbie with stupid question cont.
  • Index(es):
    • Date
    • Thread