Re: Scope of NSOperations
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