I am looking at something very strange. I have a document object, that has an 
object that it owns; which has a __weak pointer back to the document object. 
Another object also has an indirect pointer to the document object. So, 
something like this:

@interface MyDoc : NSDocument
{
        MySubObj *subObj;
}
@end

@interface MySubObj : NSDocument
{
        @public
                __weak MyDoc *doc;
}
@end

@interface SomeOtherObject : NSObject
{
        MySubObj *subObj;
}
@end

During the execution of MyDoc's init method, an instance of MySubObj is 
created, and stored in the document's ivar. During MySubObj's init method, the 
__weak pointer back to the document object is set. This seems to work OK - I've 
traced it thru in the debugger. Then, an instance of SomeOtherObject is 
created, and it's subObj ivar is set. Again, works OK. The next thing 
SomeOtherObject does is to load a local variable with a reference to the 
document object, by copying it out of MySubObj's public __weak doc pointer.

OK, now the strange part: performing that copy causes the __weak doc ivar to 
get zeroed. I''ve watched it in the debugger; before executing that line of 
code, it's got the right value; after, it's nil. Changing __weak to 
__unsafe_unretained makes the problem go away.

This is the exact line of code in question:

TrDocument *document=(TrDocument *)__RPCPersistentInfo__pool->document;

The document object in question is, when this happens, still in the middle of 
it's init method when that __weak __RPCPersistentInfo__pool->document variable 
gets zeroed out.

Has anyone ever seen anything remotely like this? How and why is it happening 
on a *read*, of all places (I would have expected it to occur on a scope 
transition, where ARC would have possibly fired to do a release)? And do I need 
to worry about other places where I'm using __weak?

Oh, and this is on 10.8, with Xcode 4.4.1.

ANY insight would be much appreciated!
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to