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

Re: Scope of NSOperations


  • Subject: Re: Scope of NSOperations
  • From: James Bucanek <email@hidden>
  • Date: Thu, 4 Feb 2010 08:42:58 -0700

McLaughlin, Michael P. <mailto:email@hidden> wrote (Thursday, February 4, 2010 6:47 AM -0500):

solverOp *thisOp = [solverOp new];
[thisOp initWithData:Data];

Wrong. You're initing your object twice! This should be

solverOp *thisOp = [[solverOp alloc] initWithData:Data];

(+new sends an -init, so your code was equivalent to [[[solverOp alloc] init] initWithData:...])

I had always *assumed* that, since an NSOperation was allocated (not just
declared), it would automatically persist long enough to do its job -- in
other words, with GC supported, retain count would trump "scope" (as above).

Standard memory management rules apply: the NSOperationQueue retains the NSOperation until it's finished. You need to retain it until you're done with with. For GC, replace "retain" with "reference".


Is the setup code fragment above correct or must NSOperations be retained in
scope explicitly until the operation is finished?

It's OK for GC, but if you're using retained memory you're missing an autorelease.


Fix your init, and you'll probably be OK.

--
James Bucanek

_______________________________________________

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: 
 >Scope of NSOperations (From: "McLaughlin, Michael P." <email@hidden>)

  • Prev by Date: Scope of NSOperations
  • Next by Date: Re: NSFullUserName() always returns the user name at app launch?
  • Previous by thread: Scope of NSOperations
  • Next by thread: Re: Scope of NSOperations
  • Index(es):
    • Date
    • Thread