discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Infinite loop in objc_storeWeak


From: David Chisnall
Subject: Re: Infinite loop in objc_storeWeak
Date: Mon, 18 Jun 2012 13:02:08 +0100

On 18 Jun 2012, at 12:02, Thomas Davie wrote:

> I get that that weak pointer shouldn't be released, I added that line in just 
> to check that it wasn't zeroed if messages were sent to it.  The bug I'm 
> referring to is the fact that the second log line prints out a pointer value 
> and description, despite the only strong pointer to o having been released.  
> By my understanding, [r target] should result in nil on line 12.

Please read my email.  As I said, the call to [r target] is creating a new 
retained/autoreleased pointer to the object.  It will therefore not work as you 
think it works.  

If you bracket the NSLog with @autoreleasepool{}, then it works as you think it 
works.  In both cases, it works as documented.  Try this and you will see that 
it works:

int main (int argc, char **argv)
{
    @autoreleasepool
    {
       NSObject *o = [[NSObject alloc] init];
       BBWeakRef *r = [BBWeakRef refWithTarget:o];
       @autoreleasepool {
           NSLog(@"%p - %@", [r target], [r target]);
       }
       [o release];
       NSLog(@"%p - %@", [r target], [r target]);
       [[r target] release]; // Should not overrelease, [r targt] should be nil 
by now.
       NSLog(@"%p - %@", [r target], [r target]);
       return 0; 
    }
}

If you wish to mix ARC and non-ARC code, then you must understand the semantics 
of ARC...

David

-- Sent from my Apple II


reply via email to

[Prev in Thread] Current Thread [Next in Thread]