• 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: NSOperationQueue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOperationQueue


  • Subject: Re: NSOperationQueue
  • From: Quincey Morris <email@hidden>
  • Date: Sat, 13 Sep 2008 09:52:35 -0700

Your code is crashing because you're doing it wrong:

On Sep 13, 2008, at 05:05, John Love wrote:

- (void) calculateWorksheet:(id)data {
   int row;
   for (row=1; row < 500; row++) {
       // long calculation here
   }
}

- (void) startQueue {
NSLog(@"start queue"); // I see this in the debugger
opData = @"not used data";
theQueue = [[NSOperationQueue alloc] init];
theOp = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(calculateWorksheet:)
object:opData];
[theQueue addOperation:theOp];
}


- (void) stopQueue {
   NSLog(@"stop queue");   // .. but I do not see this
   [theQueue cancelAllOperations];
// [theQueue release];   // done by [theOp release]
   [opData release];
   [theOp release];
}

Cancelling a NSOperation (including a NSInvocationOperation) doesn't stop it. The operation itself must detect that it was cancelled, then clean up and exit. So what this code effectively does is to release 'theOp' while it's still running. It's not surprising you're getting a crash as a result.


Also, it's not clear why you think '[theOp release]' releases 'theQueue' too. Normally, you'd expect the queue to persist for the life of your application, while the operations are created, added to the queue and destroyed as needed. There's nothing absolutely wrong with creating a new queue for every operation, I guess, but you are going to have to release the queue when the operation using it is finished.


_______________________________________________

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


References: 
 >NSOperationQueue (From: John Love <email@hidden>)

  • Prev by Date: Re: NSOperationQueue
  • Next by Date: Re: How do people typically implement dialog controllers?
  • Previous by thread: NSOperationQueue
  • Next by thread: NSOperationQueue
  • Index(es):
    • Date
    • Thread