Object not being deleted under ARC
An object created in a second object is not being dealloc'd when the second object is dealloc'd unless I set the pointer to nil in the dealloc, which doesn't seem right.  

I thought ARC was supposed to set all pointers to nil by default when the object is dealloc'd, thereby releasing any owned objects.

Here is my code (just to core):

    @interface Obj1 : NSObject
    {
        Obj2 *obj2;   
    }

    @interface Obj2 : NSObject
    {
    }

    @implementation Obj1

    -(void)dealloc
    {
        obj2 = nil;  // <--- This is needed to get obj2 to be dealloc'd.
        NSLog(@"Obj1 dealloc");
    }

    -(id)init
    {
        if ((self = [super init]) == nil)
            return nil;

        obj2 = [[Obj2 alloc] init];

        return self;
    }

    @end

    @implementation Obj2

    -(void)dealloc
    {
        NSLog(@"Obj2 dealloc");
    }

    -(id)init
    {
        if ((self = [super init]) == nil)
            return nil;

        return self;
    }

    @end

Am I doing something wrong?  Everything I've read says this should work.  No one else is holding into obj2 since setting it to nil releases it.  I've tried the code with and without the dealloc functions just in case it was messing something up and I get the same results.

Thanks.





Object not being deleted under ARC
===

An object created in a second object is not being dealloc'd when the second object is dealloc'd unless I set the pointer to nil in the dealloc, which doesn't seem right.  

I thought ARC was supposed to set all pointers to nil by default when the object is dealloc'd, thereby releasing any owned objects.

Here is my code (just to core):

    @interface Obj1 : NSObject
    {
        Obj2 *obj2;   
    }

    @interface Obj2 : NSObject
    {
    }

    @implementation Obj1

    -(void)dealloc
    {
        obj2 = nil;  // <--- This is needed to get obj2 to be dealloc'd.
        NSLog(@"Obj1 dealloc");
    }

    -(id)init
    {
        if ((self = [super init]) == nil)
            return nil;

        obj2 = [[Obj2 alloc] init];

        return self;
    }

    @end

    @implementation Obj2

    -(void)dealloc
    {
        NSLog(@"Obj2 dealloc");
    }

    -(id)init
    {
        if ((self = [super init]) == nil)
            return nil;

        return self;
    }

    @end

Am I doing something wrong?  Everything I've read says this should work.  No one else is holding into obj2 since setting it to nil releases it.  I've tried the code with and without the dealloc functions just in case it was messing something up and I get the same results.

Thanks.




