Re: updating UI during long loop using cocoa objective-c
Re: updating UI during long loop using cocoa objective-c
- Subject: Re: updating UI during long loop using cocoa objective-c
- From: Bob Smith <email@hidden>
- Date: Mon, 2 Apr 2007 14:23:13 -0700
On Apr 2, 2007, at 5:31 AM, Jerry Krinock wrote:
However one thing -runModalSession does not do is autoreleasing,
so your modal session code might need to manage it's own
autorelease pools.
Wow! Where did you read that, Bob? I have not allocced any
autorelease pools for my modal sessions, but neither have I seen
any of those "autoreleased with no pool in place -- just leaking"
messages in Console.
There is still an autorelease pool in effect, established by the run
loop before your modal session started. The issue is -
runModalSession does not release that pool; it will not be released
until after your modal session ends and you return to the regular run
loop. If your modal session code does a lot of autoreleased object
creation, directly or indirectly, you may end up with many objects
hanging around taking up memory that could be freed, especially if
your session loop might run for a very long time.
I don't recall if I read this in the docs or discovered it the hard
way; with a quick search right now I can't find any confirmation.
But it's trivial to have your loop look something like this:
while (NSRunContinuesResponse == [NSApp runModalSession:mySession]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
.
.
[pool release];
}
and it seems like it can't hurt.
Hope this helps!
Bob S.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden