[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: |
Fri, 15 Jun 2012 14:50:08 +0100 |
Can you try to produce a reduced test case? I've tried a few things and I
can't make it not work. For example, this code:
int main(void)
{
BBWeakRef *o = [BBWeakRef refWithTarget: [NSObject new]];
NSLog(@"%@", o.target);
}
Logs (null) as expected. A backtrace might help. As would compiling libobjc2
without optimisations (you can't actually be infinite looping in a loop that
counts from 0 to 3, you must be looping in the outer loop for some reason).
The most likely cause of this is that you're trying to create a weak reference
to an object that's already been deallocated. Perhaps you could try
GSZombieEnabled=YES as well?
David
On 15 Jun 2012, at 14:38, Thomas Davie wrote:
>
> On 15 Jun 2012, at 14:24, David Chisnall wrote:
>
>> Hi Thomas,
>>
>> A couple of questions:
>>
>> Are you using the release version of libobjc or svn? Your line numbers
>> don't match up with mine, so it may be that this is a bug that's already
>> fixed in svn. I'm currently waiting for Quentin to test another bug fix and
>> then I'll be doing a new release next week.
>
> Hi David,
> I was at version 1.6, I have just pulled trunk, and tried again, I'm hitting
> the same thing, but now reporting line 561 of arc.m.
>
>>
>> The second question is whether you remembered to initialise the weak pointer
>> to 0, or call objc_initWeak() for the first store?
>
> The weak pointer is an ivar, so it should be 0 initialised, yes. Just for
> completeness I've included my code below.
>
> Thanks
>
> Tom Davie
>
> BBWeakRef.h
>> #import <Foundation/Foundation.h>
>>
>> @interface BBWeakRef : NSObject
>>
>> + (id)refWithTarget:(id)target;
>> - (id)initWithTarget:(id)target;
>>
>> @property (weak) id target;
>>
>> @end
>
> BBWeakRef.m
>> #import "BBWeakRef.h"
>>
>> @implementation BBWeakRef
>>
>> @synthesize target = _target;
>>
>> + (id)refWithTarget:(id)target
>> {
>> return [[BBWeakRef alloc] initWithTarget:target];
>> }
>>
>> - (id)initWithTarget:(id)target
>> {
>> self = [super init];
>>
>> if (nil != self)
>> {
>> [self setTarget:target];
>> }
>>
>> return self;
>> }
>>
>> - (NSUInteger)hash
>> {
>> return [[self target] hash];
>> }
>>
>> - (BOOL)isEqual:(id)other
>> {
>> if ([other isKindOfClass:[BBWeakRef class]])
>> {
>> return [[(BBWeakRef *)other target] isEqual:[self target]];
>> }
>> return NO;
>> }
>>
>> @end
>
-- Sent from my PDP-11