Re: Some Questions...
Re: Some Questions...
- Subject: Re: Some Questions...
- From: j o a r <email@hidden>
- Date: Sun, 20 Jun 2004 19:20:36 +0200
On 2004-06-20, at 18.55, Jerry LeVan wrote:
>
for(i=0 ; i< fcnt ; i++) {
>
// NSImage * tmp= [[NSImage
>
alloc]initWithContentsOfFile:(NSString*)[fileNameList
>
objectAtIndex:i]];
>
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
>
NSImage * tmp = [self altMakeThumb:[fileNameList objectAtIndex:i]];
>
[[thumbArray cellAtRow:i column:0] setImage: tmp];
>
[[thumbArray cellAtRow:i column:0] setTarget:self];
>
[[thumbArray cellAtRow:i column:0] setAction:@selector(showMe:)];
>
[tmp release];
>
[filesLeft setIntValue: fileCtr--];
>
[filesLeft displayIfNeeded];
>
[pool release];
>
}
I would have done something like this:
================================================
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int i;
for (i = 0; i < someThing; i++)
{
// Do stuff
if ((i % 500) == 499)
{
[pool release];
pool = [[NSAutoreleasePool alloc] init];
}
}
[pool release];
================================================
To avoid having to empty the pool in each iteration through the loop.
In the code above (if I didn't make any mistakes - it's hacked together
in Mail) the pool is emptied every 500th iteration through the loop.
Change that number to fit your application!
Do something similar for your call to "display" - you should probably
not force a display at every iteration through the loop. If you're
doing something that's going to take so long time that you think that
you need to force display updates, you should probably spin off this
operation to a separate thread, and funnel up the results to the main
thread every so often to show progress - while still allowing the main
thread to be responsive at all times.
j o a r
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.