• 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: How can an object know when another object has gone away?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can an object know when another object has gone away?


  • Subject: Re: How can an object know when another object has gone away?
  • From: "James W. Walker" <email@hidden>
  • Date: Sun, 15 Jun 2008 17:39:34 -0700


On Jun 15, 2008, at 4:04 PM, Hamish Allan wrote:

On Sun, Jun 15, 2008 at 11:20 PM, James W. Walker <email@hidden> wrote:

Here's my specific situation. I have several controllers that can create
tasks, using an NSTask wrapper based on the Moriarty sample. When a task
completes, it sends a message to the controller that created it. If the
controller dies before the task completes, I'd like to abort the task. But
I'd prefer not to have the controllers explicitly keep track of all their
tasks.

I'm not sure I understand the problem, but presumably your controller keeps a reference to your NSTask to keep it alive; if the controller properly releases that reference when it is dealloced, the task will be terminated when the controller "dies".

No, the controller does not keep a reference to the task. Why would it need to do that in order to "keep it alive"?


After Andreas Monitzer suggested NSNotificationCenter, I used that to solve the problem to my satisfaction. When a controller is deallocated, it posts a "died" notification. Task wrappers register for that notification, and if a task wrapper receives the notification, it stops the task and autoreleases itself. If a task runs to completion, it autoreleases itself and stops observing the notification.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please 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


  • Follow-Ups:
    • Re: How can an object know when another object has gone away?
      • From: "Hamish Allan" <email@hidden>
    • Re: How can an object know when another object has gone away?
      • From: Jens Alfke <email@hidden>
References: 
 >How can an object know when another object has gone away? (From: "James W. Walker" <email@hidden>)
 >Re: How can an object know when another object has gone away? (From: "Hamish Allan" <email@hidden>)

  • Prev by Date: Re: looking for a crc code
  • Next by Date: Re: NSOutlineView threading problem
  • Previous by thread: Re: How can an object know when another object has gone away?
  • Next by thread: Re: How can an object know when another object has gone away?
  • Index(es):
    • Date
    • Thread