I have this line of code, just before a block is enqueued onto a dispatch
queue. weakSelf is used in that block.
RKHIPCard __weak *weakSelf = self;
which is generating the following error
objc[15245]: cannot form weak reference to instance (0x89b4100) of
class RKHIPCard
in certain very occasional circumstances. A bit of logging and it's clear that
those circumstances are when the RKHIPCard, self, is in the middle of being
deallocated. In other cases the object is perfectly fine for forming weak
references.
I read through the ARC spec and all the underlying methods which store into a
__weak pointer are documented something like this (this one is objc_storeWeak(
id *object, id value )
"If value is a null pointer or the object to which it points has begun
deallocation, object is assigned null and unregistered as a __weak object.
Otherwise, object is registered as a __weakobject or has its registration
updated to point to value."
That's the case we have here, value points to an object which has begun
deallocation, so it seems the language spec makes provisions for that and the
store should work and store null into the weak pointer, which would actually
work just fine.
Is this an ARC implementation bug, or is it being trapped before the
objc_xxxWeak() method is called or is that piece of the spec advisory-only and
the runtime is free not to complain loudly if you do this? It's not very hard
to work around, it's just a timing issue, in fact it's fixed already, but I had
expected the weak variable assignment to 'just work' if the object is in fact
being deallocated and was surprised that it doesn't.
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]