• 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: updating UI during long loop using cocoa objective-c
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: updating UI during long loop using cocoa objective-c (From: Bob Smith <email@hidden>)
 >Re: updating UI during long loop using cocoa objective-c (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: optimizing background image drawing with -drawRect
  • Next by Date: Re: NSObjectController can't observe NSArrayController's selection?
  • Previous by thread: Re: updating UI during long loop using cocoa objective-c
  • Next by thread: Re: updating UI during long loop using cocoa objective-c
  • Index(es):
    • Date
    • Thread